ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
How to pass the grid row key ot the Url.Action
Title:
B
I
{code}
?
I need assistance in figuring out how to send the *indicatorId* which is in the `rowmodel.IndicatorId` Here is the code I am trying to use.: ClientFormat = "<div><a href='" + Url.Action("EditNew", "Results", new { area = "", SiteID = @Model.SiteId, MechanismID = @Model.MechanismId, IndicatorID = {}, YearQuarterID = Model.YearQuarterId }) + "' class='glyphicon glyphicon-pencil')' style='display:inline-block'></a>" + in the controller the action looks like this: public ActionResult EditNew(int? SiteID, int? MechanismID, int? IndicatorID, int? YearQuarterID){}
Save Changes
Cancel
riya
asked at 22 Dec 2023
Answers
B
I
{code}
?
There are multiple ways to do this, there are a few demos shown here: https://demo.aspnetawesome.com/GridDemo/CustomFormat in the view code you could have this: var linkFormat = "<a href='" + Url.Action("EditNew", "Results", new { IndicatorId= ".(IndicatorId)", SiteId = ".(SiteId)" }) + "'>Edit</a>"; ... new Column { ClientFormat = linkFormat, --- another way, using js to generate the link: function linkBtn(model) { console.log(model); // check the object in the console, sometimes properties are camelCased, depends on your cfg (Program.cs) return "<a href='/Results/EditNew?IndicatorId=" + model.IndicatorId + "&SiteId="+ model.SiteId + "'>Edit</a>"; } ... new Column { ClientFormatFunc = linkBtn,
Save Changes
Cancel
Omu
answered at 22 Dec 2023
Site is coming from the ViewModel and the indicator is the key to the list of Indicators within the ViewModel. I am NOT able to get the SiteId using Model.SiteId. Can't figure out either how to get the IndicatorID based on the row of the grid I am selecting. I tried doing this. Not able to get the IndicatorId
at 22 Dec 2023
riya
ClientFormatFunc = "actionColumn", function actionColumn(model) { if (!model.isIndicatorType) { return "<div><a href='" + Url.Action("EditNew", "Results", new { area="", SiteID=@Model.SiteId, IndicatorID= model.IndicatorId}) + "' '></a><div>"; }}
at 22 Dec 2023
riya
if you put the `@Model.SiteId` in the ClientFormat you'll have one single value for all the rows, you can modify the grid row model in the action that returns data to the grid ( `Grid().Url(ControllerActionIndicatedHere)` ), in that action you have a `GridModelBuilder` where you set a `Map` function, we use this in almost all of our demos, including the CustomFormat link mentioned in my answer, have a look at the controller code
at 22 Dec 2023
Omu
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK