asp.net-mvc-3 – Html.RenderPartial和Ajax.BeginForm – > Submit被调用两次

前端之家收集整理的这篇文章主要介绍了asp.net-mvc-3 – Html.RenderPartial和Ajax.BeginForm – > Submit被调用两次前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下索引视图:
@model BoringStore.viewmodels.ProductIndexviewmodel
@{
    ViewBag.Title = "Index";
}

<h2>Produkte</h2>

<div id='addProduct'>
    @{ Html.RenderPartial("Create",new BoringStore.Models.Product()); }
</div>

<div id='productList'>
    @{ Html.RenderPartial("ProductListControl",Model.Products); }
</div>

“productList”只是所有产品的列表.

addProduct渲染我的创建视图:

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<div id="dialog-confirm" title="Produkt hinzufügen" style="display:none">
@using (Ajax.BeginForm("Index_AddItem",new AjaxOptions { UpdateTargetId = "productList" }))
{ 
    @Html.Raw(DateTime.Now.ToString());

    <div>
        @Html.LabelFor(model => model.Name)
        @Html.EditorFor(model => model.Name)
    </div>
    <br />
    <div>
        @Html.LabelFor(model => model.Price)
        @Html.EditorFor(model => model.Price)
    </div>
    <br /><br />
    <div>
        <input type="submit" value="Produkt hinzufügen" />
    </div>
}

提交表单时,我的控制器中的Index_AddItem方法调用.不幸的是,表单总是调用方法两次. 原文链接:/aspnet/249889.html

猜你在找的asp.Net相关文章