Javascript 上传图像-模式弹出窗口MVC不';关不上
我有问题。我在上打开我的网站,例如:localhost:9999/Product/Index 当我单击“创建”图标时,它会显示一个带有页面/产品/板条箱的模式弹出窗口 我点击保存 数据库中的所有记录都正确,但它将我重定向到页面/产品/板条箱,我只想关闭我的模式窗口 我该怎么办 型号:Javascript 上传图像-模式弹出窗口MVC不';关不上,javascript,asp.net-mvc,serialization,modal-dialog,Javascript,Asp.net Mvc,Serialization,Modal Dialog,我有问题。我在上打开我的网站,例如:localhost:9999/Product/Index 当我单击“创建”图标时,它会显示一个带有页面/产品/板条箱的模式弹出窗口 我点击保存 数据库中的所有记录都正确,但它将我重定向到页面/产品/板条箱,我只想关闭我的模式窗口 我该怎么办 型号: public partial class Prod { public string ProductName { get; set; } public string ProductDescriptio
public partial class Prod
{
public string ProductName { get; set; }
public string ProductDescription { get; set; }
public byte[] PFile { get; set; }
}
@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>
}
[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);
}
索引视图:
public partial class Prod
{
public string ProductName { get; set; }
public string ProductDescription { get; set; }
public byte[] PFile { get; set; }
}
@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>
}
[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);
}
@使用(Html.BeginForm(“创建”、“产品”、FormMethod.Post、新建{
enctype=“多部分/表单数据”}){
@ActionLink(“,”创建“,”产品“,”空,新{data_modal=“”,id=“btnCreate”,@class=“btn btn small
btn主拉右固定资产车加“})
@ActionLink(“,”创建“,”产品“,”空,新{id=
“btnCreate”@class=“btn btn小btn主拉右fa
fa cart plus“})}
创建视图:
public partial class Prod
{
public string ProductName { get; set; }
public string ProductDescription { get; set; }
public byte[] PFile { get; set; }
}
@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>
}
[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
$(函数(){
}))
函数绑定窗体(对话框){
请帮助解决此问题。我们尝试删除行
location.reload();
,这将防止页面在不更改的情况下重新加载。有人有什么想法吗?