4
我想創建一個類似於Ajax.ActionLink
的幫助程序。我創建了一個幫手有了一些變化要做到這一點:如何爲Ajax.ActionLink定製幫助程序
@helper AjaxLink(string innerhtml, string href, string targetId)
{
if (!string.IsNullOrEmpty(innerhtml))
{
if (href.Trim() == "#")
{
<a href="@(href)">
@MvcHtmlString.Create(innerhtml)
</a>
}
else
{
<a href="@(href)" data-ajax-update="#@(targetId)" data-ajax-mode="replace">
@MvcHtmlString.Create(innerhtml)
</a>
}
}
}
幫助我創建像一個鏈接:
<a href="ItemRegister?testTypeId=1" data-ajax-update="#pageId" data-ajax-mode="replace">
<i class="fa fa-sign-out"><span style="right: -47px;" class="icon-bg bg-orange"></span></i><span>Register </span>
</a>
但它不工作!它刷新頁面,而不是填充目標
我做到了,但不是工作呢! –
但它在我的系統上工作得很好 – Behzad
哦,我忘了連接到'jquery.unobtrusive-ajax.js'。你是對的!謝謝 –