Как я должен написать это, чтобы Бритва не ускользает все биты и качается:Мой HTML Helper в настоящее время narlified от Razor
вспомогательный класс (по иронии судьбы не то, что полезно)
public static class TableHeaderSortingHelpers
{
public static string SortTableClickEvent(this HtmlHelper html, string url, string column)
{
string sortingPropertiesObject;
sortingPropertiesObject = "var properties = new James.prototype.Table.SortingProperties();";
sortingPropertiesObject += "properties.url = '" + url + "';";
sortingPropertiesObject += "properties.colName = '" + column + "';";
sortingPropertiesObject += "onclick = 'James.Table.SortByColumn(properties, this);'";
return sortingPropertiesObject ;
}
}
вид Razor
<table class="table table-striped">
<tr>
<th width="100%" @Html.SortTableClickEvent(@Request.Path, "Name");>
Name
</th>
После компиляции выглядит следующим образом:
<th width="100%" this);';="" 'name';onclick="'James.Table.SortByColumn(properties," =="" james.prototype.table.sortingproperties();properties.url="'/Site/List';properties.colName" properties="new" var="">
Name
</th>
EDIT //////////////////////
Если я пытаюсь вернуть MVCHtmlString я получаю следующее:
public static class TableHeaderSortingHelpers
{
public static MvcHtmlString SortTableClickEvent(this HtmlHelper html, string url, string column)
{
string sortingPropertiesObject;
sortingPropertiesObject = "var properties = new James.prototype.Table.SortingProperties();";
sortingPropertiesObject += "properties.url = '" + url.ToString() + "';";
sortingPropertiesObject += "properties.colName = '" + column + "';";
sortingPropertiesObject += "onclick = 'James.Table.SortByColumn(properties, this);'";
MvcHtmlString returnString = new MvcHtmlString(sortingPropertiesObject);
return returnString;
}
}
Выход
<th width="100%" ;="" ;onclick="James.Table.SortByColumn(properties, this);" ;properties.colname="Name" james.prototype.table.sortingproperties();properties.url="/Site/List" properties="new" var="">
Name
</th>
Можете ли вы опубликовать пример своего ожидаемого результата? Причина, по которой я спрашиваю, заключается в том, что 'var properties = ...' будет заканчиваться непосредственно в тэге 'th'. –