Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
<pre lang="C#">@using (Html.BeginForm(new { id = "companyinfo"}))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
<fieldset>
//Some code.........
<pre lang="XML">&lt;fieldset&gt;</pre>

 
}

</pre>

this is my code for form and i want to give an ID. But when I submit this form it gives the error at.....

C#
<pre lang="C#">&lt;pre lang=&quot;C#&quot;&gt;[HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Create(CompanyMaster companymaster)
      {

              if (ModelState.IsValid)
              {
                  db.CompanyMaster.Add(companymaster);
                  db.SaveChanges();
                  return RedirectToAction(&amp;quot;Index&amp;quot;);
              }

          return View(companymaster);

      }&lt;/pre&gt;


At ModelState that the attribute &quot;companyinfo&quot; is not valid here.........</pre>
Posted

@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { id = "companyinfo"}))
{
    
}
 
Share this answer
 
MVC 5 and lower:
HTML
@using (Html.BeginForm(null, null, FormMethod.Post, new {id="companyinfo"}))
   { 

} 

MVC 6 : You can use tag helpers to avoid the odd syntax for setting the id.
HTML
<form asp-controller="Account" asp-action="Register" method="post" id="companyinfo" role="form"></form>
 
Share this answer
 
Comments
Member 11392252 27-Nov-15 5:19am    
I've already tried this..... and then posted here.....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900