I have the code below, which works fine. Suppose I now want to change something in the ActionLinkButton
method, like add another
parameter to its signature. I would then have to change the call in .cshtml as well, of course. However, there is no compile error if I don't change the
.cshtml, the application just crashes when attempting to display the View
, getting directed to the default error html page.There is no detail of the error in the logs, in firebug, anywhere.
Obviously, I should try to remember to check all calls when I make such a change, but I forget.
So, how can I prevent this error or make it easier to trace?
1. Some sort of Razor syntax checker?
2. Some way of directing to an error page with some meaningful message?
.cs
public static MvcHtmlString ActionLinkButton(
this HtmlHelper htmlHelper,
string buttonText,
string actionName,
string controllerName,
RouteValueDictionary routeValues,
Boolean enable)
{
string href = UrlHelper.GenerateUrl("default", actionName, controllerName, routeValues, RouteTable.Routes, htmlHelper.ViewContext.RequestContext, false);
// title is tooltip
string buttonHtml;
if (enable)
{
buttonHtml = string.Format("<input type=\"button\" title=\"Export\" value=\"{0}\" onclick=\"location.href='{1}'\" class=\"button\" />", buttonText, href);
}
else // disable button
{
buttonHtml = string.Format("<input type=\"button\" disabled=\"disabled\" title=\"Export\" value=\"{0}\" onclick=\"location.href='{1}'\" class=\"button\" />", buttonText, href);
}
return new MvcHtmlString(buttonHtml);
}
.cshtml
@Html.ActionLinkButton(
buttonText: "Export",
actionName: "Export",
controllerName: "Detail",
routeValues: new RouteValueDictionary(new {PermitId = @Model.PermitId }),
enable : false)