#C #MVC #Razor Html Helper
Unencoded Expression
<span>@Html.Raw(model.Message)</span>
@using Health.Web.Web.Framework
// PARENT PAGE
@section PageScriptContent {
@Html.RenderScripts()
}
// MODAL PARENT PAGE
</script>
....
</script>
@Html.RenderScripts()
// PARTIAL OR EDITOR (CHILD)
@Html.Script(
@<script>
$(document).ready(function () {
});
</script>
)
@Html.Action("DocumentListMenu", "Common", new { Area = "" })
public static MvcHtmlString Partial(
this HtmlHelper htmlHelper,
string partialViewName,
object model,
ViewDataDictionary viewData)
SAMPLE 1
@if (Model.Insureds != null)
{
for (int i = 0; i < Model.Insureds.Count; i++)
{
var viewDataDict = new ViewDataDictionary
{
new KeyValuePair<string, object>("Prefix", "Insureds[" + i + "]"),
new KeyValuePair<string, object>("EndorsementType", Model.EndorsementType.ToString()),
new KeyValuePair<string, object>("InsuredId", Model.Insureds[i].Id)
};
@Html.Partial("_Insured", Model.Insureds[i], viewDataDict)
}
}
SAMPLE 2
var insuredTemplate = '@Html.Partial("_Insured",
new PolicyInsuredViewModel(),
new ViewDataDictionary()
{
{ "DFormIsClosed", Model.Product != null && Model.Product.DFormIsClosed },
{ "ProductId", Model.ProductId }
}).ToString().NormalizeHtmlResponse()';
var $insuredRow = $('<div>' + insuredTemplate + '</div>');
public static MvcHtmlString NormalizeHtmlResponse(this string partialHtml)
{
if (String.IsNullOrEmpty(partialHtml))
{
return MvcHtmlString.Create(partialHtml);
}
string lineSeparator = ((char)0x2028).ToString();
string paragraphSeparator = ((char)0x2029).ToString();
return MvcHtmlString.Create(
partialHtml
.Replace("\r\n", string.Empty)
.Replace("\n", string.Empty)
.Replace("\r", string.Empty)
.Replace(lineSeparator, string.Empty)
.Replace(paragraphSeparator, string.Empty)
.Replace("'", "\'")
.Replace("\"", "\"")
);
}
SAMPLE 1
<tbody>
@if (Model.Targets != null && Model.Targets.Count > 0)
{
foreach (var target in Model.Targets.OrderBy(model => model.TargetStart))
{
Html.RenderPartial("_AgentCommissionProtocolTarget", target);
}
}
</tbody>