locked
Nested Form with an MVC View Page RRS feed

  • Question

  • User-554427789 posted

    Problem: If there is a nested form within the MVC view content page, then it will only post the outermost form only.

    For example: I have a login form as such:

     
    <form action="/Security/Authenticate" method="post">
    
    <input id="userName" name="userName" type="text"/> 
    
    <input id="password" name="password" type="password"/>
    
    <input type="submit" value="submit"/> 
    
    </form> 

     but it will always post to the Index method of the SecurityController class instead of the authenticate method.

    Temporary solution: I have put a </form> before the start of the new <form> tag to make it work.

    This will also work if an MVC View Page is used instead.

     Hope it helps.
     

    Tuesday, January 22, 2008 8:24 PM

All replies

  • User-1902356349 posted

    Nested forms are not supported in the HTML standard, so browsers need not necessarily support them.

    (NOT an mvc question!)

     

    what you might be able to do is give the form an Id, getElementById(), and call submit on that instead of using a submit button. 

     

    Tuesday, January 22, 2008 9:09 PM
  • User-554427789 posted

     Yup I know it is not an MVC question, yet it is so closely related to actual MVC development that putting in this thread makes sense ( as opposed to sandwiching it in some Html thread).

    I like your suggestion on the javascript postback. I will try it out and post the results. 

    Tuesday, January 22, 2008 9:18 PM
  • User1609037590 posted

    What if I disable javascript? Your solution will break. Its too obtrusive.

     You can have multiple submits per form all with name="submit" and have a submit parameter on the controller action. It means you have to switch over the submit value but ive found the solution to be maintainable.
     

    Friday, January 25, 2008 7:01 AM