Calling Html Helper Method from Javascript Function

I am trying to call a custom Html helper method that I have written from a javascript function that is used by jqGrid to return formatted text, in this case a link, for a cell:

function formatGroupPlanEditLink(cellValue, options, rowObject) {
        //var cellHtml = "<a href='/Insurance/GroupPlanEdit/?id=" + rowObject[0] + "'>" + rowObject[1] + "</a>";
    var functionArgs = rowObject[1] + ',Url.Action("GroupPlan", "Insurance", new { id = ' + rowObject[0] + ' }),String.Format("Edit {0}", ' + rowObject[1] + '), listId,Url.Action("GroupPlanList", "Insurance"),false';
    var cellHtml = '@Html.DialogFormLink(' + functionArgs + ')';
    return cellHtml;
}

The problem that I have is that I cannot concatenate the entire string before the helper is executed. So the browser is trying to execute "@Html.DialogFormLink(" - which of course causes an error. I guess there must be a better way to go about this. I really want to still be able to use the Html helper method as I use it elsewhere, and it works nicely for my requirements.

Answers:

Answer

I'm not that familiar with Razor, but the quotes around the @Html helper look suspicious.

var cellHtml = '@Html.DialogFormLink(' + functionArgs + ')';

The browser doesn't execute @Html.DialogFormLink; the server evaluates it. I suspect the server is injecting the literal '@Html.DialogFormLink' into your js.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.