How to embed content in Ajax.ActionLink

In Asp.net mvc3 razor I have:

Ajax.ActionLink("Hello world", "Hello", "Say", new RouteValueDictionary(new { word = "Hello" }),new AjaxOptions { HttpMethod = "GET", InsertionMode = InsertionMode.Replace, UpdateTargetId = "dynamic-container" })

he produces

<a href="...." ...>Hello world</a>

What I would like to receive

<a href="..." ...><my><html><content/></html></my></a>

How can I pass "" so that it is inserted instead of the standard text?

+3
source share
4 answers

I just found a solution

http://forums.asp.net/post/4517653.aspx

It is not as elegant as I expected, but should have done.

Anyone have a better idea?

+5
source

the code:

Ajax.ActionLink("Hello world", "Hello", "Say", new RouteValueDictionary(new { word = "Hello" }),new AjaxOptions { HttpMethod = "GET", InsertionMode = InsertionMode.Replace, UpdateTargetId = "dynamic-container" })

with the provided link leads to an error. The link is as follows:

.../Say/Hello?Count=1&Keys=System.Collections.Generic.Dictionary%602%2BKeyCollection%5BSystem.String%2CSystem.Object%5D&Values=System.Collections.Generic.Dictionary%602%2BValueCollection%5BSystem.String%2CSystem.Object%5D

which is BAAADDDDD .... the problem is that it uses the wrong overload. Instead:

new RouteValueDictionary(new { word = "Hello" })

where should be:

 new { word = "Hello" }

when the code forms a link in the previous answer, it works like a charm - I hope that it will be useful for someone, someone

0

javascript/jQuery . " ", .

, HtmlAttributes @Ajax.Action, , JS:

@Ajax.ActionLink(.....  new { @class = "AjaxLink btn btn-primary" })

javascript/jQuery, (-) , innerHTML . jQuery, javascript. jQuery, :

<script type="text/javascript">
//hack to insert a <span> inside the remove links so that the text can be styled                
$('.AjaxLink ).html('<i class="fa fa-minus-circle"></i><span class="ActionLinkText">Your Text here</span>');

</script>

,

0

@4rchie, , . , data- * jquery .

:

<div class="list-group">
@foreach (var item in Model.Things)
{
   @Ajax.ActionLink(item.Name, "actionName", "controllerName", new { Id = item.Id }, new AjaxOptions { HttpMethod = "GET", InsertionMode = InsertionMode.Replace, UpdateTargetId = "areaPanel", OnComplete = "" }, new { @class = "list-group-item", data_frequency = item.frequency})

}
</div>

JQuery:

jQuery(document).ready(function () {
$("[data-frequency]").each(function () {
        var linkText = $(this).html();
        var attr = $(this).attr("data-frequency");
        $(this).html("<span class ='badge'>" + attr + "</span>" + linkText);
})
}

http://getbootstrap.com/components/#list-group-badges

0

All Articles