Reputation: 77
I am new to MVC.How to Edit data in popup MVC3 razor.I goggled a lot but did not get it. I am using jquery. My controller-
[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");
}
Upvotes: 1
Views: 3124
Reputation: 5992
you will have to use Ajax.ActionLink which can return the partial view and then that result would be added to the div and then OnSuccess you show that partial view.
@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");
}
Upvotes: 1
Reputation: 1038720
You may take a look at the jQuery UI dialog component which allows you to achieve that.
Upvotes: 2