0

我正在尝试使用一种表单来允许用户选择一个日期并通过 url 参数将其传递回控制器。我的意图是让表单提交一个看起来像 Payroll/Index/id?employeeID="foo"?DayInWeekInput="bar" 的 url。相反,这会生成 url Payroll/Index/id? 所以我显然做错了什么。我怎样才能用表格做到这一点?如果不可能,你能解释一下替代方案吗?谢谢。

using (Html.BeginForm("Index", "Payroll", new { id = @ViewBag.SupervisorID, employeeID=@ViewBag.EmployeeID }, FormMethod.Get))
{
    @*@Html.AntiForgeryToken()*@
    @Html.ValidationSummary(true)

    <div class="editor-field">
        <input type="date" id="DayInWeekInput" value="@string.Format("{0:yyyy-MM-dd}", Model.SpecifiedWeekStart)" />
        <input type="submit" value="Go" />
    </div>                       
}
4

1 回答 1

0

您停止命名,如果您保留名称,它应该对您有用

using (Html.BeginForm("Index", "Payroll", new { id = @ViewBag.SupervisorID, EmployeeID = @ViewBag.EmployeeID, DaysInWeekInput = "bar" }, FormMethod.Get))

既然这对你不起作用,我接下来会尝试一个 ajax 调用

$('.btnSubmit').on('click', function(){
    $.ajax({
        url: '@Url.Action( "Index", "Payroll" )',
        data: { 
            id: @ViewBag.SupervisorID,
            EmployeeID:  @ViewBag.EmployeeID
        },
        success: function (_result) {
            if (_result.Success) {

            }
        }
    });
});

我还建议将您的 id 放在隐藏字段中。Viewbag 可能不稳定。

于 2013-10-16T14:59:47.167 回答