如何确定表单上的控件提交给控制器mvc asp.net

时间:2013-02-19 21:05:01

标签: javascript asp.net-mvc

我有一个表单会提交给控制器两次:一个控制下拉框内容的表单和第二个下拉列表,一旦你失去焦点,它应该调用验证并提交。

查看:

<%=Html.DropDownListFor(l => Model.LOAAccessTypeId, loaAccessTypeItems, new { @onblur = "this.form.submit();" }) %>
<%:Html.DropDownListFor(l => Model.PersonSelectedId, loaPersonItems, new { @onblur = "this.form.submit();" }) %>

控制器:

ValidateData(loa);

if (ModelState.IsValid)
{
    if (loa.LOAOrReferredById == 2)
        loa.LOAAccessTypeId = -1;

    SaveLOA(loa);
    return RedirectToAction("PlanCreate", "Plan", new { id = mloa.PersonId });
}

private void ValidateData(LOA loa)
{
    if (loa.LOAOrReferredById == 1)
    {
        if (loa.LOAAccessTypeId == -1)
            ModelState.AddModelError("LOATypeId", "Select an LOA Type");

        if (loa.EMDRepresentativeId == null && loa.LOAPersonId == null && loa.IssuerId == null && loa.AgentId == null)
            ModelState.AddModelError("EMDRepId", "Please select a person or a company");
    }

    if (loa.LOAOrReferredById == 2)
    {
        if (loa.EMDRepresentativeId == null && loa.IssuerId == null && loa.AgentId == null)
            ModelState.AddModelError("EMDRepId", "Please select a person or a company");
    }
}

理想情况下,我不希望在人员点击第二个下拉框之前触发ValidateData()。我知道为ASP.Net表单填充的EventTarget,但是对于MVC,FormCollection中的相同参数为null。

我如何知道哪个下拉框失去焦点并调用控制器?

0 个答案:

没有答案