0

我使用 asp.net mvc 3 和 jquery article遵循渐进增强教程。但我有一个问题。当我提交表单时,如果出现错误,它不会在 jquery ui 对话框中显示部分视图并重定向整个页面。请指导我。\

这是我的控制器:

public ActionResult ManualRecharge(int id)
    {
        Bank bank = db.Banks.Find(id);
        if (Request.IsAjaxRequest())
        {
            return PartialView("_ManualRecharge",bank);
        }
        return View(bank);
    }

    [Authorize(Roles = "admins")]
    [HttpPost]
    [ValidateAntiForgeryToken]
    [OutputCache(Duration = 0)]
    public ActionResult ManualRecharge(Bank model)
    {
        if (model.Availible < 0)
        {
            ModelState.AddModelError("Availible", "نمی تواند کوچکتر از 0 باشد");
        }
        if (model.Creadit < 0)
        {
            ModelState.AddModelError("Creadit", "نمی تواند کوچکتر از 0 باشد");
        }
        if (!ModelState.IsValid)
        {
            // If the incoming request is an Ajax Request 
            // then we just return a partial view (snippet) of HTML 
            // instead of the full page
            if (Request.IsAjaxRequest())
                return PartialView("_ManualRecharge", model);

            return View(model);
        }

这是部分视图

@model Stockala.Models.Bank


@{
    Layout = null;
}
<style type="text/css">
    body{direction:rtl;}
</style>

@using (Ajax.BeginForm("ManualRecharge", null, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "rechargDialog" }, new { id = "Form1" }))
{
    @Html.ValidationSummary(true)
    @Html.AntiForgeryToken()
    @Html.HiddenFor(model => model.BankID)
    @Html.HiddenFor(model => model.UserName)
    <fieldset>
        <legend>بانک شخصی @Model.UserName</legend>
            <table class="fields">
        <tr>
            <td class="label">
                @Html.LabelFor(model => model.Creadit) :
            </td>
            <td class="editor-field">
                @Html.TextBoxFor(model => model.Creadit, new { title = "لطفا " + "موجودی" + " را وارد کنید" })
                @Html.ValidationMessageFor(model => model.Creadit)
            </td>
        </tr>
        <tr>
            <td class="label">
                @Html.LabelFor(model => model.Availible) :
            </td>
            <td class="editor-field">
                @Html.TextBoxFor(model => model.Availible, new { title = "لطفا " + "قابل برداشت" + " را وارد کنید" })
                @Html.ValidationMessageFor(model => model.Availible)
            </td>
        </tr>
        <tr>
            <td colspan="2">
            <p>
                <input type="submit" value="تایید" class="button" id="SubmitButton"/>
            </p>
            </td>
        </tr>
    </table>    
    </fieldset>


}

我做错了什么?

编辑:这是我的父页面

    <div id="dvOrders">
        <table>
    <tr>
        <th>
            کاربر
        </th>
        <th>
            موجودی
        </th>
        <th>
            قابل برداشت
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.UserName)
        </td>
        <td>
            @item.Creadit.ToString("N0")
        </td>
        <td>
            @item.Availible.ToString("N0")
        </td>
        <td>
            @Html.ActionLink("تنظیم دستی حساب", "ManualRecharge", "Bank", new { id = item.BankID }, new { @class = "controls money openDialog", target = "_blank", title = "تنظیم دستی حساب", data_dialog_id = "rechargDialog", data_dialog_title = "شارژ حساب", width = "500" }) 
        </td>
    </tr>
}

</table>



<div id="pager-div">
     @Html.AjaxPager(Model, new PagerOptions() { PageIndexParameterName = "id", CurrentPagerItemWrapperFormatString = "<span class=\"cpb\">{0}</span>", NumericPagerItemWrapperFormatString = "<span class=\"item\">{0}</span>", CssClass = "pages", SeparatorHtml = "", FirstPageText = "ابتدا", NextPageText = "بعدی", LastPageText = "انتها", PrevPageText = "قبلی", ShowDisabledPagerItems = false, ShowPageIndexBox = true, PageIndexBoxType = PageIndexBoxType.DropDownList, ShowGoButton = false }, new AjaxOptions() { UpdateTargetId = "dvOrders", OnBegin = "AjaxStart", OnComplete = "AjaxStop" })
        </div>
        </div>

这是我的页面,它在没有 ajax 的情况下加载

@model Stockala.Models.Bank

@{
    ViewBag.Title = "تنظیم حساب";
    Layout = "~/Views/Shared/_LayoutEmpty.cshtml";
}


@Html.Partial("_ManualRecharge")
4

0 回答 0