views:

435

answers:

2

My ASP.NET MVC app opens and displays the dialog fine however I can't figure out how to get DB content into it. I have read about making an ajax call to get the data. My disconnect is how it gets displayed in my . Any links where this is done (full code).

Thanks.

+1  A: 

You have to create a different action that returns the "DB content":

public SomeController : Controller 
{
  public ActionResult DatabaseData()
  {
    var model = getDatabaseData();
    return View(model);
  }
}

And create the corresponding view, that displays the data in a div.

After this you can load the result of this action in your dialog:

$('#id-of-dialog-element')
  .load('<%=Url.Action("DatabaseData", "SomeController")%>')
  .dialog('open');

Alternatively, you could return the DB data as JSON and render the data in a table on the client.

Jan Willem B
I previously had tried this using this code ( I need to pass an id to my controller action) but it never hit my controller code. How do I dynamically pass id with your version? Here's mine. Also can you provide a snippet of how to handle the return in my dialog div. I know - pretty basic. Thanks. onClickButton: function() { var data = $("#equipgrid").getRowData(curRow); jQuery('#img_dialog').load("/EquipTrak/GetEquipImages/" + data.equip_id); jQuery('#img_dialog').dialog('open'); return false; },
MikeD
your code looks ok to me. If it does not hit the code, you have probably made a mistake somewhere. What do you mean by "how to handle the return in my dialog div"? injecting javascript params in the urls can be done like this: var url = '<%=Url.Action("GetEquipImages", "EquipTrak", new { id = "__id__" })%>'; url = url.replace(/__id__/, data.equip_id);
Jan Willem B
The code either way is not hitting my controller action breakpoint. What am I missing?
MikeD
It's equiptrack, not equiptrak :)
Jan Willem B
I did find that as well. Thanks. Now the error I get is that there is no view called GetEquipImages. Do I need to use a partial. Or do I need to create a view called GetEquipImages.
MikeD
It seems to me that you lack some basic knowledge about the tools you are using to do the task you are doing. Maybe you should do some reading on asp.net mvc first to prevent getting stuck on trivial things.
Jan Willem B
A: 

I am closing this and opening another more specific issue. Thanks.

MikeD