Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to get the HTML values into MVC Controller

What I have tried:

@foreach (var items in ViewBag.Load)
{
<table border="1" align="center">
<tr>
<th>Id:</th>
<th><input type="text" value="@items.Id" disabled="disabled" /></th>
</tr>
<tr>
<th>Name:</th>
<th><input type="text" value="@items.Name" id="txtName" /></th>
</tr>
<tr>
<th>Phone:</th>
<th><input type="text" value="@items.Phone" /><br /></th>
</tr>
<tr>
<th>DeptName</th>
<th><input type="text" value="@items.DeptName" /></th>
</tr>
<tr>
<th colspan="2">
@Html.ActionLink("Update", "Updatedata");
</th>
</tr>
</table>
}
public ActionResult Updatedata(FormCollection frc)
       {
           Person p1 = new Person();
           p1.Id = Convert.ToInt32(frc["Id"]);
           p1.Name = frc["Name"];
           p1.Phone = Convert.ToInt64(frc["Phone"]);
           Person1Database database = new Person1Database();
           if(database.Updatedata(p1)==1)
           {
               ViewBag.status = "update";
           }
           return RedirectToAction("Load");

       }
Posted
Updated 21-Jul-17 5:39am

1 solution

I think you may need to follow a tutorial in regards to asp.net mvc. I am assuming you copied all the HTML for your form (otherwise you left out the @using(Html.BeginForm html helper.

A simple google search of "Html forms in ASP.net MVC" will render plenty of links to help you solve this question. But the short of it is, you are missing

@using(Html.BeginForm("", "")) which should be wrapped around your entire html form.

FormExtensions.BeginForm Method (System.Web.Mvc.Html)[^]

Html forms in ASP.net MVC - Google Search[^]

ASP.NET MVC 4 Helpers, Forms and Validation | Microsoft Docs[^]
 
Share this answer
 

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