asp.net mvc3中的错误 [英] error in asp.net mvc3
问题描述
我是MVC的新手.您好完成了小项目.当我点击编辑动作链接时,应该会弹出我写的很好.当弹出窗口显示时,当我单击保存按钮时,我在编辑弹出窗口中更改了数据.它没有消失.请帮助我
这是我的代码.在这里,我将editorstemplate保留在该文件夹Editinput.cshtml中的一个文件夹中,当我单击Edit时它将显示所有字段.
电影控制器.
I am new to MVC. Hi have done small project. when i click on edit actionlink it should popup i wrote its working fine. when popup displays i changed the data in edit popup when i click on save button. its not disappearing. please help me
here is my code. here i kept editorstemplate one folder in that folder Editinput.cshtml it will display all fields when i click on edit.
Movie Controller.
public ActionResult Edit(int id)
{
Movies movies = db.Movies.Find(id);
return PartialView(movies);
}
//
// POST: /Movies/Edit/5
[HttpPost]
public ActionResult Edit(Movies movies)
{
if (ModelState.IsValid)
{
if (Request.IsAjaxRequest())
{
db.Entry(movies).State = EntityState.Modified;
db.SaveChanges();
return View("Index", movies);
}
}
return RedirectToAction("Index");
}
在Index.cshtml中.
in Index.cshtml.
@model IEnumerable<MVCSampleProject.Models.Movies>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
Title
</th>
<th>
ReleaseDate
</th>
<th>
Genre
</th>
<th>
Price
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.ReleaseDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.Genre)
</td>
<td>
@Html.DisplayFor(modelItem => item.Price)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.ID }, new { @class="openDialog",data_dialog_id="emailDialog", data_dialog_title="Edit"})
@Html.ActionLink("Details", "Details", new { id=item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.ID })
</td>
</tr>
}
</table>
在Edit.cshtml中.
in Edit.cshtml.
@model MVCSampleProject.Models.Movies
<h2>Edit</h2>
@Html.Partial("_Edit")
_Edit.cshtml
_Edit.cshtml
@model MVCSampleProject.Models.Movies
@using (Ajax.BeginForm(new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "emailDialog" }))
{
@Html.ValidationSummary(true)
@Html.EditorForModel()
<p>
<input type="submit" value="Save" />
</p>
}
EditInput.cshtml.cs
EditInput.cshtml.cs
@model MVCSampleProject.Models.Movies
<h2>Editinfo</h2>
<fieldset>
<legend>Movies</legend>
@Html.HiddenFor(model => model.ID)
<div class="editor-label">
@Html.LabelFor(model => model.Title)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Title)
@Html.ValidationMessageFor(model => model.Title)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ReleaseDate)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ReleaseDate)
@Html.ValidationMessageFor(model => model.ReleaseDate)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Genre)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Genre)
@Html.ValidationMessageFor(model => model.Genre)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Price)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Price)
@Html.ValidationMessageFor(model => model.Price)
</div>
</fieldset>
}
这是我的JavaScript代码
here my javascript code
<script type="text/javascript">
$.ajaxSetup({ cache: false });
$(document).ready(function () {
$(".openDialog").live("click", function (e) {
e.preventDefault();
$("<div></div>")
.addClass("dialog")
.attr("id", $(this)
.attr("data-dialog-id"))
.appendTo("body")
.dialog({
title: $(this).attr("data-dialog-title"),
close: function () { $(this).remove() },
modal: true
})
.load(this.href);
});
$(".close").live("click", function (e) {
e.preventDefault();
$(this).closest(".dialog").dialog("close");
});
});
</script>
请帮我谢谢.
问候
Sreekanth.
please help me thank you.
regards
Sreekanth.
推荐答案
.ajaxSetup({cache:false});
.ajaxSetup({ cache: false });
(document).ready(function(){
(document).ready(function () {
(.openDialog").live("click",函数(e){ e.preventDefault();
(".openDialog").live("click", function (e) { e.preventDefault();
这篇关于asp.net mvc3中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!