开发者

Ajax equivalent of UrlHelper.Action in Asp.Net MVC 3.0

How can I generate an AJAX URL in my .cs file in开发者_如何学JAVA MVC 3.0?

Normally I use this code for a normal URL:

UrlHelper url = new UrlHelper(HttpContext.Current.Request.RequestContext);

string link = url.Action("actionName", routeValues)

But I'm looking for a way to create some sort of a link, like the one you create in a View with

@Ajax.ActionLink("linkText", "actionName", routeValues, ajaxOptions)


I just got this answered for my AjaxHelper extension. I had to use MergeAttributes and ToUnobstrusiveHtmlAttributes Here is the relevant code:

        Dim anchorBuilder = New TagBuilder("a")
        anchorBuilder.MergeAttribute("href", url.Action(action, controller, routeValues))
        anchorBuilder.MergeAttributes(AjaxOptions.ToUnobtrusiveHtmlAttributes)
        anchorHtml = anchorBuilder.ToString(TagRenderMode.Normal)

Link to my question: Custom AjaxHelper extension, merging AjaxOptions

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜