本文介绍了如何将HTML值导入MVC控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将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");

       }

推荐答案


这篇关于如何将HTML值导入MVC控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 21:34