tags:

views:

70

answers:

2

Any one Know How to give name to a form in Asp.net MVC Html.BeginForm() i want only name not action or controller name because i want to post it through Java Script. Something like this Html.BeginForm(id = "frm")

i tried Html.BegainForm(null,null,new{id="frm",name="frm})

Html.BegainForm(new{@id="frm",@name="frm})

But Above code Produce Code Like This

when see through View Source

+2  A: 
Html.BeginForm(null, null, FormMethod.Get, new { name = "frm", id = "frm" })

You'll need to catch the form submit with your JavaScript

BritishDeveloper
Thanks But your solution produce this code <form action="/Main/Index/frm?name=frm" method="post">
right you are. yeah, I've corrected it now
BritishDeveloper
Thanks It Works Man Thank Again
A: 

Taken from this answer: http://stackoverflow.com/questions/878330/how-to-pass-in-id-with-html-beginform

Can you not just do:

Html.BeginForm(new {@id="Id", @name="Id"}); 

It can pay to search SO for answers as I've found many things I want to ask have already been encountered.

Paul Hadfield
you're adding route values though. not html attributes
BritishDeveloper
I see your answer where you're passing in nulls, I did think you could just use the defaults for the named parameters and pass in a list of additional attributes to append to the output HTML
Paul Hadfield
i tried your solution before but it generate code like this "<form action="/Main/Index/Id?name=Id" method="post">"
Sorry about that, I did think that was the way it worked - obviously not. In that case, this might be a good example of when to provide your own HTML extension method, or just revert back to good old HTML.
Paul Hadfield