views:

1995

answers:

3

Context
Let`s say i have:
In layout Site.Master:

<div class="leftColumn">
    <asp:ContentPlaceHolder ID="MainContent" runat="server" />
</div>
<div class="rightColumn">
    <% Html.RenderPartial("_Login"); %>
    <asp:ContentPlaceHolder ID="SideContent" runat="server" />
</div>

Login partialView looks like:

<form action="/myApp/Account/Login" method="post">
    <input name="name" />Name<br />
    <input name="password" type="password" />Password<br />
    <button>Login</button>
</form>

Is it possible to update only login widget form, not the entire content page?

A: 

if(pass != true) { ViewData["Message'] = "Hey your login failed!"; Return View("Login") }

On ViewPage <form action="/tralala/Account/Login" method="post"> <input name="name" />Name<br /> <input name="password" type="password" />Password<br /> <button>Login</button> <div style="color: red"><%=ViewData["Message"] %><div> </form>

Skiltz
You missed the point. Question was - how to update 1 form only, if that is possible, not how to use ViewData dictionary.
Arnis L.
Sorry dude, I keep reading your question and I don't understand what you are asking.
Skiltz
I`m just asking, if page with 2 <form> elements can update only 1 of them at the time, not touching the other one.
Arnis L.
A: 

Your question is not very clear.

But as far as I could understand, the answer is most likely yes. You can update anything you want depending on the user input.

çağdaş
I also don't understand what you are asking... can you please edit your question to give some more context. Your first 'form' is badly formed and doesn't have any input elements... What is it for? I thought that the modelviewstate only updates the fields that it tried to bind...? Is that a login widget or a login page? Or are you having issues with the Validation Messages and validation highlighting? I had to create some custom HTMLHelper extensions to handle multiple forms but I really don't know if they apply here because I can't understand what your problem is... some more info would help.
Charlino
I'm really sorry. English is not my native too. I'll try to edit question.
Arnis L.
+3  A: 

If you are referring to a http post, only a post initiated (it can also be initiated by javascript) by a submit button from within the form will be posted to the server.

If your forms are nested then this won't work. The outer form will always post to the server.

In the sample HTML below, clicking on the submit button on the first form will not send the values from the second form to the server. Likewise, clicking the second submit button won't post the values from the first form.

<html>
...
  <body> 
    <div>

      <form action="/Login/Login" method="post">
        <input type="text" name="username" value="" />
        <input type="text" name="passowrd" value="" />
        <input type="submit" name="login" value="Login" />
      </form>


      <form action="/Login/AdminLogin" method="post">
        <input type="text" name="username" value="" />
        <input type="text" name="passowrd" value="" />
        <input type="submit" name="login" value="Login Admin" />
      </form>
    </div>
</body>
</html>

If you only wish to update/change one of the form section, then no this can not be done without using javascript and performing a javascript post(aka Ajax).

Chuck Conway
Yay... Despite that question surely was unclear, this is exactly what i wanted to hear: "If you only wish to update/change one of the form section, then no this can not be done without using".So far it seems, that there aren`t a clean way to implement so called widgets in asp.net mvc. :/
Arnis L.
This isn't a limitation of MVC - you are asking to update part of the page only so you have to do something client side (e.g. AJAX/JS) as ALL HTML forms by their definition will change page when submitted.
Graphain
Question just hit 'popular' badge mark. Amazingly to see how much I've learned. Such a stupid question. :D
Arnis L.