0

我有一个定义如下的表格。

<% using (Html.BeginForm("PRoll", "Payroll", FormMethod.Post, new { @id = "frmPRoll" })){%>

    <%= Html.TextBoxFor(model => model.keyid, new { @class = "required", Style = "width:190px", @maxlength = "15" })%>
    ....
<% } %>

控制器为

public ActionResult Index(int? id)
{
    var bo = new PayrollInfo();
    return View(bo);
}

[HttpPost]
public ActionResult DetailPage(string keyid)
{
    //TempData["prid"] = p_payrollid;
    return RedirectToAction("PayDtl/" + keyid, "Payroll", keyid);
}

我通过jquery提交表单如下

function DetailPage() {
    var rol = $('#keyid').val();
    $('#frmPRoll').attr('action', '/Proll/DetailPage/'+rol).submit();
}

控制器 DetailPage 操作方法中的 keyid 值始终为空。它永远不会被视图中的实际数据填充。

如何从控制器的视图中获取 keyid 值?

谢谢

4

2 回答 2

2
function DetailPage() {
    // TODO: don't hardcode /Proll/DetailPage here: use url helpers
    $('#frmPRoll').attr('action', '/Proll/DetailPage').submit();
}

Since there's already a textbox within this form containing the keyid value, when you submit the form to the DetailPage action, this value will be POSTed as the keyid action parameter.

Also you are using a wrong overload of the RedirectToAction method. It should be like this, assuming of course that your PayDtl expects an argument called keyid:

[HttpPost]
public ActionResult DetailPage(string keyid)
{
    return RedirectToAction("PayDtl", "Payroll", new { keyid = keyid });
}
于 2012-07-26T15:08:00.750 回答
0

尝试这个

function DetailPage() {
    var rol = $('#keyid').val();
    $.ajax({
            type: "POST",
            url: '@Url.Action("DetailPage", "Proll")',
            data: "keyid=" + rol
            success: function (result) {
            ...
    });
});
于 2012-07-26T15:02:04.093 回答