How to Show modal popup in mvc3?

ghihi picture ghihi · Jun 22, 2012 · Viewed 10.2k times · Source

I need to show details on the popup. I don't have any idea how to do this. I need to do it in a MVC3 Razor view.

my Controller-

public ViewResult ViewDetail(Int32 id)
{
  var q = from p in db.accs
          where p.id == id
          select p;
  return View(q.FirstOrDefault());
}

my View-

<td>@ Html.ActionLink("View Detail", "ViewDetail", new { id=item.id }) </td>

Answer

McGarnagle picture McGarnagle · Jun 22, 2012

This kind of task isn't really what ASP.NET MVC / Razor does. Consider using a Javascript library like JQuery UI Dialog. You have to add several of the JQuery UI scripts to your page, but the payoff is a very simple API; you can create a basic dialog out of any HTML element (say with id mydiv) with one line of code:

$( "#mydiv" ).dialog();

And of course there are customizations and themes you can apply.

Of course, you could simply use the Javascript:

alert("my details here");

to get a basic modal popup, but I'm guessing that's not what you want.