actionlink

Raw ActionLink linkText

只愿长相守 提交于 2019-11-28 08:40:01
I want to put a button as the text of an @ActionLink() but I can't because it HTML-escapes my string... I found the @Html.Raw() mechanism and have tried the @ActionLink().ToHtmlString() but can't figure out how to put it together... I found an article that describes building an extension for a similar purpose but it's eeky to go to that much trouble... there must be an easy way? You could write a helper: public static class HtmlExtensions { public static IHtmlString MyActionLink( this HtmlHelper htmlHelper, string linkText, string action, string controller, object routeValues, object

Create an ActionLink with HTML elements in the link text

半腔热情 提交于 2019-11-28 06:15:40
In an ASP.NET MVC view I'd like to include a link of the form: <a href="blah">Link text <span>with further descriptive text</span></a> Trying to include the <span> element in the linkText field of a call to Html.ActionLink() ends up with it being encoded (as would be expected). Are there any recommended ways of achieving this? You could use Url.Action to build the link for you: <a href="<% =Url.Action("Action", "Controller")%>">link text <span>with further blablah</span></a> or use Html.BuildUrlFromExpression: <a href="<% =Html.BuildUrlFromExpression<Controller>(c => c.Action()) %>">text <span

Using HTML tags inside linkText of Html.ActionLink

江枫思渺然 提交于 2019-11-28 00:42:45
Is it possible to use HTML tags in the linkText of Html.ActionLink? For instance, if I wanted to bold part of the text of a link I would try something similar to this: <%= Html.ActionLink("Some <b>bold</b> text", "Index")%> but that just outputs Some <b>bold</b> text I know I could do this by using an anchor tag and setting the URL with Url.Action, but I just wanted to know if this was possible. No; it's not possible. You need to manually write an <a> tag. The Html.ActionLink helper HTML encodes the link text which prevents you from embedding HTML in the link text. For this same reason you

MVC make action link perform a submit

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 00:14:44
问题 I am currently trying to make an html submit occur, but using the MVC helper method ActionLink as I do not want it to be a button, I want it to be an underlined link like the rest on my page. This is what I have currently <%= Html.ActionLink("Delete Selected", "DeleteCheckBox", "Domains", "Default.aspx", new { type="submit" }) %> This jumps back to my action fine, but all the domains that are checked off to be deleted are not sent back. (if I use this, <input type="submit" name="DeleteAction"

Delete ActionLink with confirm dialog

拜拜、爱过 提交于 2019-11-27 17:46:07
I'm trying to implement a simple ActionLink that will delete records using ASP.NET MVC. This is what I have so far: <%= Html.ActionLink("Delete", "Delete", new { id = item.storyId, onclick = "return confirm('Are you sure?');" })%> However, it doesn't show the confirm box. Clearly I'm missing something or I have incorrectly built the link. Can anyone help? Don't confuse routeValues with htmlAttributes . You probably want this overload : <%= Html.ActionLink( "Delete", "Delete", new { id = item.storyId }, new { onclick = "return confirm('Are you sure you wish to delete this article?');" }) %>

MVC ActionLink add all (optional) parameters from current url

☆樱花仙子☆ 提交于 2019-11-27 11:43:03
The very famous ActionLink : <%: Html.ActionLink("Back to List", "Index")%> Now, this link is in my Details view. The Index view is a search page. The URL of that looks like this: http://localhost:50152/2011-2012/Instelling/Details/76?gemeente=Dendermonde&postcode=92**&gebruikerscode=VVKSO114421&dossiernr=114421%20&organisatie=CLB As you can see, quite the amount of parameters. Obviously I want to keep all these parameters when I return to the Index page, so I need to add them in the ActionLink . Now, I'm tired of doing that manually, it's ok for 1, but not for 6. This should go a lot easier.

ASP.NET MVC - Pass array object as a route value within Html.ActionLink(…)

假装没事ソ 提交于 2019-11-27 09:23:48
I have a method that returns an array (string[]) and I'm trying to pass this array of strings into an Action Link so that it will create a query string similar to: /Controller/Action?str=val1&str=val2&str=val3...etc But when I pass new { str = GetStringArray() } I get the following url: /Controller/Action?str=System.String%5B%5D So basically it's taking my string[] and running .ToString() on it to get the value. Any ideas? Thanks! Try creating a RouteValueDictionary holding your values. You'll have to give each entry a different key. <% var rv = new RouteValueDictionary(); var strings =

Image button in ActionLink MVC

谁说胖子不能爱 提交于 2019-11-27 07:46:06
问题 How to put image instead text in ActionLink button: @Html.ActionLink("Edit-link", "Edit", new { id=use.userID }) So how to change text "Edit-link" to image? Thanks for any idea. 回答1: do like this: <a href="@Url.Action("Edit")" id="@use.userID"> <img src="@Url.Content("~/images/someimage.png")" /> </a> or pass both action and controller name by using other override: <a href="@Url.Action("Edit","Controller")" id="@use.userID"> <img src="@Url.Content("~/images/someimage.png")" /> </a> UPDATE:

How can I include a bookmark/fragment in an ActionLink? [duplicate]

不羁的心 提交于 2019-11-27 06:50:57
问题 Possible Duplicate: Including an anchor tag in an asp.net mvc Html.ActionLink The code : @Html.ActionLink("Link", "Action", "Controller", new { id = Id } ) For the moment I can generate links like this : http://mywebsite/Controller/Action/Id I would like to generate a link like this : http://mywebsite/Controller/Action/Id#divId But I can't edit the route/create another route. What is the best solution? 回答1: Just use the proper overload of the ActionLink helper: @Html.ActionLink( linkText:

ActionLink htmlAttributes

两盒软妹~` 提交于 2019-11-27 06:46:51
WORKS <a href="@Url.Action("edit", "markets", new { id = 1 })" data-rel="dialog" data-transition="pop" data-icon="gear" class="ui-btn-right">Edit</a> DOES NOT WORK - WHY? @Html.ActionLink("Edit", "edit", "markets", new { id = 1 }, new {@class="ui-btn-right", data-icon="gear"}) It seems you can't pass something like data-icon="gear" into htmlAttributes? Suggestions? The problem is that your anonymous object property data-icon has an invalid name. C# properties cannot have dashes in their names. There are two ways you can get around that: Use an underscore instead of dash (MVC will automatically