我有问题 . 我打开我的网站,例如:localhost:9999 / Product / Index

当我单击“创建”图标时,显示带有页面/产品/包装箱的模态弹出窗口

我单击“保存” .

数据库中的所有记录都正确,但它将我重定向到page / Product / Crate,我只想关闭我的模态窗口 .

我做什么sholuld?

Model:

public partial class Prod
{
    public string ProductName { get; set; }
    public string ProductDescription { get; set; }
    public byte[] PFile { get; set; }
}

Index View:

@using(Html.BeginForm(“Create”,“Products”,FormMethod.Post,new {enctype =“multipart / form-data”})){@ Html.ActionLink(“”,“Create”,“Products” ,null,new {data_modal =“”,id =“btnCreate”,@ class =“btn btn-small btn-primary pull-right fa fa-cart-plus”})@ Html.ActionLink(“”,“Create” ,“产品”,null,new {id =“btnCreate”,@ class =“btn btn-small btn-primary pull-right fa fa-cart-plus”})}

Create View:

@using (Html.BeginForm("Create", "Products", FormMethod.Post, new { id = "form1", enctype = "multipart/form-data" }))
        {
            @Html.AntiForgeryToken()

            <div class="modal-body">

                <div class="form-horizontal">
                    @Html.ValidationSummary(true, "", new { @class = "text-danger" })

                    <div class="form-group">
                        @Html.LabelFor(model => model.ProductName, "Name", htmlAttributes: new { @class = "control-label col-md-3" })
                        <div class="col-md-9">
                            @Html.EditorFor(model => model.ProductName)
                            @Html.ValidationMessageFor(model => model.ProductName, "", new { @class = "text-danger" })
                        </div>
                    </div>

                    <div class="form-group">
                        @Html.LabelFor(model => model.ProductDescription, "Name", htmlAttributes: new { @class = "control-label col-md-3" })
                        <div class="col-md-9">
                            @Html.EditorFor(model => model.ProductDescription)
                            @Html.ValidationMessageFor(model => model.ProductDescription, "", new { @class = "text-danger" })
                        </div>
                    </div>

                    <div class="form-group">
                        @Html.LabelFor(model => model.PFile, "File", htmlAttributes: new { @class = "control-label col-md-3" })
                        <div class="col-md-9">
                            @Html.TextBoxFor(model => model.PFile, new { type = "file", name = "imageF" })
                            @Html.ValidationMessageFor(model => model.PFile, "", new { @class = "text-danger" })
                        </div>
                    </div>

                </div>

            </div>

            <div class="modal-footer">
                <button class="btn" data-dismiss="modal">Anuluj</button>
                <input class="btn btn-primary" type="submit" value="Zapisz" />
            </div>
        }

Controller:

[HttpPost]
        [AcceptVerbs(HttpVerbs.Post)]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Exclude = "PFile")] Prod pro, HttpPostedFileBase imageF)
        {                    
            if (ModelState.IsValid)
            {

                    if (imageF != null)
                    {
                        pro.PFile= new byte[imageF.ContentLength];
                        imageF.InputStream.Read(pro.PFile, 0, imageF.ContentLength);
                    }


                     db.Prods.Add(pro);
                     db.SaveChanges();
                     return Json(new { success = true });

            }

            return PartialView("Create", pro);
        }

modalform.js

$(function(){$ .ajaxSetup({cache:false});

$(“a [data-modal]”) . on(“click”,function(e){

//隐藏下拉列表(如果有)
$(e.target).closest( 'BTN-组 . ')儿童(' 下拉菜单,切换 ')下拉菜单(' 切换') . ;

$('#myModalContent') . load(this.href,function(){

$( '#myModal') . 模态({
/ * backdrop:'static',* /
键盘:是的
}, '节目');

bindForm(本);
});

返回虚假;
});
}); function bindForm(dialog){$('form1',dialog).submit(function(){
$就({
url:this.action,
类型:this.method,
data:$('#file') . serialize(),
contentType:'multipart / form-data',
成功:功能(结果){
if(result.success){
$( '#myModal')模态( '隐藏') .
//刷新
location.reload();
} else {
$( '#myModalContent')HTML(结果);
bindForm();
}
}
});
返回虚假;
}); }

请帮忙解决这个问题 .