Asp.net mvc 3 如何在MVC3中显示弹出窗口
我是MVC新手。如何在弹出式MVC3 razor中编辑数据。我目不转睛地看了很多东西,但都没看懂。 我正在使用jquery。 我的控制器-Asp.net mvc 3 如何在MVC3中显示弹出窗口,asp.net-mvc-3,razor,popup,Asp.net Mvc 3,Razor,Popup,我是MVC新手。如何在弹出式MVC3 razor中编辑数据。我目不转睛地看了很多东西,但都没看懂。 我正在使用jquery。 我的控制器- [HttpGet] public ActionResult Edit(int id) { var q = from p in db.accs where p.id == id select p; return View(q.FirstOrDefa
[HttpGet]
public ActionResult Edit(int id)
{
var q = from p in db.accs
where p.id == id
select p;
return View(q.FirstOrDefault());
}
[HttpPost]
public ActionResult Edit(int id,account ac)
{
acc a = (from p in db.accs
where p.id==id
select p).Single();
if (ModelState.IsValid)
{
a.f_name = ac.f_name;
a.l_name = ac.l_name;
a.Address = ac.Address;
a.Phoneno = ac.Phoneno;
db.SubmitChanges();
int i = 2;
return RedirectToAction("Display", new { i = i });
}
else
{
return View("Edit");
}
您可以查看允许您实现这一点的组件。您必须使用Ajax.ActionLink,它可以返回部分视图,然后将结果添加到div中,然后成功显示该部分视图
@Ajax.ActionLink(“popup”、“SomeAction”、新AjaxOptions{HttpMethod=“GET”、UpdateTargetId=“result”、InsertionMode=InsertionMode.Replace、OnSuccess=“openPopup”})
$(文档).ready(函数(){
$(“#结果”)。对话框({
自动打开:错误,
标题:“标题”,
宽度:500,
高度:“自动”,
莫代尔:对
});
});
函数openPopup(){
$(“#结果”)。对话框(“打开”);
}
什么意思?您想要一个带有表单的弹出窗口还是弹出div?你希望它是ajax还是普通的帖子?我只想通过验证编辑细节,但不知道如何编辑?
@Ajax.ActionLink("popup", "SomeAction", new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "result", InsertionMode = InsertionMode.Replace, OnSuccess="openPopup" })<br />
<div id="result" style="display:none;"></div>
<script type="text/javascript">
$(document).ready(function() {
$("#result").dialog({
autoOpen: false,
title: 'Title',
width: 500,
height: 'auto',
modal: true
});
});
function openPopup() {
$("#result").dialog("open");
}