使用HttpGet和HttpPost进行MVC 4处理

时间:2017-01-11 23:09:41

标签: asp.net-mvc

我正在使用带有Razor View的MVC 4。该视图有两个Dropdown列表和一个Submit按钮。

<form  id="mutualTradeFormId" method="get" action="@Url.Action("Index")">
     <div class="col-sm-2">
        <select id="FundFamilyId" name="FundFamily" class="FundFamilyClass">
            @foreach (var item in Model.MutualFundFamilies)
            {
                <option value="@item.Value">@item.Text </option>  
            }
        </select>
    </div>
    <select id="FundId" name="Fund" class="FundClass">
        @foreach (var item in Model.mutualFunds)
        {
            <option value="@item.Value">@item.Text</option>  
        }
    </select>
    <div class="col-sm-2">
        <input type="button" id="btnPreview" value="Preview Order" />
    </div>
</form>

要加载第二个DropdownList,我使用AJAX来电,这就是<form>代码使用Get代替Post

的原因
$(document).on("change", '#FundFamilyId', function (e) {
    SubmitFormjs();
});
function SubmitFormjs() {
    var form = $('#mutualTradeFormId');
    $.ajax({
        type: form.attr('method'),
        url: form.attr('action'),
        data: form.serialize(),
        success: function (data) {
            $('#fundListId').replaceWith(data);
        },
        error: function (xhr) {
            alert("An error occured: " + xhr.status + " " + xhr.statusText);
        }
    });
};

CONTROLLER

public ActionResult Index( string FundFamily = "")
{
    if (FundFamily.Length > 0)
    {
        _vmfund.lstMutualFunds = DalOrders.GetFundsByFamilyId(FundFamily);
    }
    ....
    return View(_vmfund);
}

表单标记包含method="get",以便填充第二个DropdownList。对于按钮点击,我想做一个帖子,我不知道如何构建控制器来为DDL填充HttpGet和点击按钮HttpPost

0 个答案:

没有答案