How to add ID property to Html.BeginForm() in asp.net mvc?


How to add ID property to Html.BeginForm() in asp.net mvc?



I want to validate my form using jquery but it doesn't have an ID property as of now how to add it to the form in asp.net mvc? I am using this...

<% using (Html.BeginForm()) {%> 

and my jquery validator plugin takes this,

var validator = $("#signupform").validate({ 

Now i want to give id as signupform... Any suggestion...


Anonymous Type syntax in ASP.NET MVC

1:

can hidden variables value be accessed in a controller in MVC
This should receive the id added.. var javascript to asp.net MVC model ASP.NET MVC 5 and lower:. Route always goes to the first maproute
<% using (Html.BeginForm(null, null, FormMethod.Post, new { id = "signupform" }))    { } %> 
ASP.NET Core 1.0 MVC: You must use tag helpers to avoid the odd syntax for setting the id.. How to pass a delegate to create an expression tree that is a MethodCallExpression
<form asp-controller="Account" asp-action="Register" method="post" id="signupform" role="form"></form> 
Forms Authentication & IIS7 (&MVC): Why ReturnUrl=/ is added?Can i access ValidationMessage through jquery in asp.net mvc

2:

Internet Explorer Nested Form Post
In System.Web.Mvc.Html ( in System.Web.Mvc.dll ) the begin form is defined like:- Details.
BeginForm ( this HtmlHelper htmlHelper, string actionName, string controllerName, object routeValues, FormMethod method, object htmlAttrialthough es) .
Means you should use like this :.
Html.BeginForm( string actionName, string controllerName,object routeValues, FormMethod method, object htmlAttrialthough es).
So, it worked in MVC 4.
@using (Html.BeginForm(null, null, new { @id = string.Empty }, FormMethod.Post,     new { @id = "signupform" })) {     <input id="TRAINER_LIST" name="TRAINER_LIST" type="hidden" value="">     <input type="submit" value="Create" id="btnSubmit" /> } 

3:

I've added any code to my project, so it's more convenient.. HtmlExtensions.cs:.
namespace System.Web.Mvc.Html {     public static class HtmlExtensions     {         public static MvcForm BeginForm(this HtmlHelper htmlHelper, string formId)         {             return htmlHelper.BeginForm(null, null, FormMethod.Post, new { id = formId });         }          public static MvcForm BeginForm(this HtmlHelper htmlHelper, string formId, FormMethod method)         {             return htmlHelper.BeginForm(null, null, method, new { id = formId });         }     } } 
MySignupForm.cshtml:.
@using (Html.BeginForm("signupform"))  {     @* Some fields *@ } 


92 out of 100 based on 67 user ratings 562 reviews