我有一个强类型 View ,并且我尝试使用 BeginForm 将单击按钮时文本框中的输入传递到操作。我的代码不断将空对象传递给 Controller 中的操作方法。如何通过表单将对象传递给 Controller ?
@using (@Html.BeginForm("GetQueueInfoWorkorder","Home", FormMethod.Post, new { id = Model}))
{
@Html.TextBoxFor(x=> x.ID);
<input type="Submit" value ="Search" class="ui-button-icon-secondary"/>
}
这是操作方法:
[HttpPost]
public ActionResult GetQueueInfoWorkorder(UserResponse id)
{
//Check queue complete
int woNumber = Convert.ToInt32(id);
tb_QueueCompleted completed = db.tb_QueueCompleted.SingleOrDefault(x => x.WorkOrderNumber == woNumber);
if (completed != null)
{
var u = new UserResponse { ID = completed.QueueId.ToString() };
GetLogInfoCompleted(u);
return View("GetLogInfo");
}
//check queue pending
return View();
}
最佳答案
我认为你已经相当接近了,但是进行这些更改并且它应该按预期工作:
型号:
public class UserResponse
{
public int ID { get; set; }
}
查看:
@model UserResponse
@using (Html.BeginForm("GetQueueInfoWorkorder", "Home"))
{
@Html.TextBoxFor(x => x.ID);
<input type="Submit" value ="Search" class="ui-button-icon-secondary"/>
}
操作方法:
public ActionResult GetQueueInfoWorkorder(UserResponse model)
{
int woNumber = model.ID;
//...
}
关于c# - 使用 BeginForm() 将对象传递给 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24632528/