如何将HTML值导入MVC控制器 [英] How to get the HTML values into MVC controller
问题描述
如何将HTML值导入MVC Controller
我尝试过的事情:
@foreach(ViewBag.Load中的可变项)
{
< table border ="1" align ="center">
< tr>
< th> Id:</th>
< th><输入类型="text" value ="@ items.Id" disabled ="disabled"/></th>
</tr>
< tr>
< th>名称:</th>
< th><输入type ="text" value ="@ items.Name" id ="txtName"/></th>
</tr>
< tr>
< th电话:</th>
< th><输入类型="text" value ="@ items.Phone"/>< br/></th>
</tr>
< tr>
< th&deptName</th>
< th><输入type ="text" value ="@ items.DeptName"/></th>
</tr>
< tr>
< th colspan ="2">
@ Html.ActionLink("Update","Updatedata");
</th>
</tr>
</table>
}
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");
}
推荐答案
我认为您可能需要遵循有关asp.net mvc的教程.我假设您复制了表单的所有HTML(否则,您就忽略了@using(Html.BeginForm html helper.
一个简单的Google搜索"ASP.net MVC中的HTML表单"将提供大量链接,以帮助您解决此问题.但是,最短的是,您不见了
@using(Html.BeginForm(",")),应将其包装在整个html表单中.
FormExtensions.BeginForm方法(系统.Web.Mvc.Html) [ ASP.net MVC中的HTML表单-Google搜索 [ ^ ]
ASP.NET MVC 4帮助器,表单和验证| Microsoft文档 [ ^ ]
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[^]
这篇关于如何将HTML值导入MVC控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!