actionlink

Using HTML tags inside linkText of Html.ActionLink

孤人 提交于 2019-11-27 04:45:59
问题 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. 回答1: No; it's not possible. You need to manually write an <a> tag. 回答2: The Html.ActionLink helper

asp.net mvc Html.ActionLink() keeping route value I don't want

谁都会走 提交于 2019-11-27 03:53:29
I have the following ActionLink in my view <%= Html.ActionLink("LinkText", "Action", "Controller"); %> and it creates the following URL http://mywebsite.com/Controller/Action Say I add an ID at the end like so: http://mywebsite.com/Controller/Action/53 and navigate to the page. On this page I have the markup I specified above. Now when I look at the URL it creates it looks like this: http://mywebsite.com/Controller/Action/53 (notice the addition of the ID) But I want it to remove the ID and look like it did originally, like this http://mywebsite.com/Controller/Action (notice no ID here) Any

What's the difference between RouteLink and ActionLink in ASP.NET MVC?

≡放荡痞女 提交于 2019-11-27 03:07:24
I think that the title pretty much sums it up: What's the difference between RouteLink() and ActionLink() in ASP.NET MVC? i.e. when do you use Html.RouteLink() and when do you use Html.ActionLink() in your View? Action and Routes don't have to have a 1:1 relationship. ActionLink will generate the URL to get to an action using the first matching route by action name. RouteLink will generate a URL to a specific route determined either by name or route values. Actually, the output from the two methods is the same, but it is generated in slightly different ways: Html.ActionLink() makes it easy to

Raw ActionLink linkText

我的梦境 提交于 2019-11-27 02:20:54
问题 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? 回答1: You could write a helper: public static class HtmlExtensions { public static IHtmlString MyActionLink( this

Create an ActionLink with HTML elements in the link text

こ雲淡風輕ζ 提交于 2019-11-27 01:14:34
问题 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? 回答1: 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

Putting HTML inside Html.ActionLink(), plus No Link Text?

不想你离开。 提交于 2019-11-26 21:20:23
I have two questions: I'm wondering how I can display no link text when using Html.ActionLink() in an MVC view (actually, this is Site.Master ). There is not an overloaded version that does not allow link text, and when I try passing in just a blank string , the compiler tells me it needs a non-empty string. How can I fix this? I need to put <span> tags within the anchor tag, but it's not working with Html.ActionLink(); . I'd like to see the following output: Span text How can I put tags inside of the anchor tag in ASP.NET MVC? Instead of using Html.ActionLink you can render a url via Url

Delete ActionLink with confirm dialog

∥☆過路亽.° 提交于 2019-11-26 19:14:04
问题 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? 回答1: Don't confuse routeValues with htmlAttributes . You probably want this overload: <%= Html.ActionLink( "Delete", "Delete", new { id =

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

旧时模样 提交于 2019-11-26 14:40:28
问题 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! 回答1: Try creating a RouteValueDictionary holding your values.

ActionLink htmlAttributes

≡放荡痞女 提交于 2019-11-26 12:56:08
问题 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? 回答1: The problem is that your anonymous object property data-icon has an invalid name. C# properties

Html.ActionLink as a button or an image, not a link

两盒软妹~` 提交于 2019-11-26 12:38:42
In the latest (RC1) release of ASP.NET MVC, how do I get Html.ActionLink to render as a button or an image instead of a link? Late response but you could just keep it simple and apply a CSS class to the htmlAttributes object. <%= Html.ActionLink("Button Name", "Index", null, new { @class="classname" }) %> and then create a class in your stylesheet a.classname { background: url(../Images/image.gif) no-repeat top left; display: block; width: 150px; height: 150px; text-indent: -9999px; /* hides the link text */ } I like to use Url.Action() and Url.Content() like this: <a href='@Url.Action(