I am wondering if there is any sample code / API that can process the output after calling HtmlHelper.Partial(...). In many cases, we use the same partial view to render the repeating items and also the template for when the user adds new items at the client. The '#' character is the trouble. In many cases a # character is used in an <a href='#'... or else where which is not part of the template. Recently, I just used the following code to get around the href='#' issue,
var template = html.Partial(...);
string str = template.ToHtmlString();
str = str.Replace("href=\"#\"", "href=\"\\\\#\"");
str = str.Replace("href='#'", "href='\\\\#'");
return new MvcHtmlString(str);
it would be great if someone had a regex or a helper function that could escape all the non-template '#' characters. I would really be unfortunate if I have to duplicate all my partial views just make them template safe.