asp.net mvc 4 - append id to actionlink jquery dialog -
this i'm looking have row of items has open button should open dialog has item inside of it, can't url post correctly. in adding diagram question saw how stackoverflow pops dialog , that's need do. problem need url /controller/action?id= (id being passed in)
url /controller/action?/7
or if rewrite action get/controller/action?/7
how rid of slash or post correctly?
actionlink
@html.actionlink("open", "additems", new { id = item.id }, new { @id = "itemdialog" })
jquery
$('#dialog').dialog({ autoopen: false, width: 400, resizable: false, modal: true }); $('#itemdialog').on("click", function () { var url = $(this).attr('href'); $('#dialog').load(url, function () { $(this).dialog('open'); }); return false; });
controller:
public actionresult additems(int id) { var tradeitem = in db.items i.id == id select i; var results = titem; return partialview("_openitem", results); //need open in dialog }
view
@model ienumerable<item> <table> <tr> <th> @html.displaynamefor(model => model.id) </th> <th> @html.displaynamefor(model => model.user_id) </th> <th> @html.displaynamefor(model => model.item_name) </th> <th> @html.displaynamefor(model => model.item_description) </th> <th> @html.displaynamefor(model => model.item_code) </th> <th> @html.displaynamefor(model => model.dateadded) </th> <th> @html.displaynamefor(model => model.catid) </th> <th></th> </tr> @foreach (var item in model) { <tr> <td> @html.displayfor(modelitem => item.id) </td> <td> @html.displayfor(modelitem => item.user_id) </td> <td> @html.displayfor(modelitem => item.item_name) </td> <td> @html.displayfor(modelitem => item.item_description) </td> <td> @html.displayfor(modelitem => item.item_code) </td> <td> @html.displayfor(modelitem => item.dateadded) </td> <td> @html.displayfor(modelitem => item.catid) </td> </tr> } </table> @html.actionlink(send db )
you leave routevalues
blank, , append query string end:
<a id="itemdialog" href='@url.action("additems")?id=@item.id'>open</a>
i think that's more straightforward way set query string -- using routevalues
implies want construct url based on route definitions.
Comments
Post a Comment