如何将文本框值传递给@html.hidden()以转到我的控制器MVC 我的观点是:
@using (Html.BeginForm("Reject", "Maker", FormMethod.Get))
{
<div class="filed">
<form class="RejectForm">
<p> <input type="text" class="RejectTextBox" name="HidField" id="HidField" value="" placeholder="سبب الرفض">
@Html.ValidationMessage("_strRejectReason", new { @style = "color:red" })</p>
<br />
<input id="RejectButton" type="submit" value="Reject"/>
</form>
</div>
@Html.HiddenFor(model => model._strRejectReason, new { id = "HidField"})
@Html.Hidden("id", item.Id);
<p>@Html.ValidationMessage("CustomError", new { @style = "color:red" })</p>
}
问题是我的控制器收到模型包含的模型的空对象 两个属性int id,string _strRejectReason我用@ Html.Hidden()发送它们;但是作为参数的控制器中的模型对象是空的,我的控制器是:
public ActionResult Reject(MakerTransactions MakerTransactions)
{
MakerCheckerUnitOfWorkBase _MakerCheckerUnitOfWorkBase = new MakerCheckerUnitOfWorkBase();
MakerTransactions.RouteAgentsConfigsMaker = _MakerCheckerUnitOfWorkBase.RouteAgentsConfigsChecker.RejectMaker(MakerTransactions.id,MakerTransactions._strRejectReason);
return View(MakerTransactions);
}
答案 0 :(得分:0)
@using (Html.BeginForm("Reject", "Maker", FormMethod.Get))
{
@Html.HiddenFor(model => model._strRejectReason)
@Html.Hidden("id", item.Id);
<p>@Html.ValidationMessage("CustomError", new { @style = "color:red" })</p>
}
MVC使用标签中的名称。然后,当您添加具有不同名称的标记ID时,服务器无法识别此属性。
@Html.HiddenFor(model => model._strRejectReasonm, new {id = "sample" })
public ActionResult Reject(FormCollection collection)
{
var _strRejectReason = collection["_strRejectReason"];
var id = collection["id"];
return View();
}