Web Forms :: RouteUrl In Markup With Changes Values?
Jun 23, 2010
I would like to build hyperlinks into my website who implement the routing techniques from ASP.NET 4.0. but ik can't seem to find a way to use the RouteUrl with changing values
[Code]....
In the code above (part of a GridView) i would like to bind to the routename "CustomerRoute" en provide the parameter "CustomerID" which gets its value from the field "CustomerID". But his doesn't seem to work.
I just upgraded to MVC3 final and a part of my site that used to work has totally stopped working. Any idea where my URL's have gone or how to get them back?
Global
routes.MapRoute( "SingleArticle", "Articles/{action}/{year}/{month}/{day}/{key}", new { controller = "Articles", action = "Archive", year = 0, month = 0, day = 0, key = "" }, new { year = @"d{4}", month = @"d{2}", day = @"d{2}" } );
cshtml
var routeLinkData = new { action = "Archive", year = item.PublishDate.Value.Year, month = item.PublishDate.Value.Month, day = item.PublishDate.Value.Day, key = item.NameKey }; URL="@Url.RouteUrl("SingleArticle", routeLinkData)" Link="<a href="@Url.RouteUrl("SingleArticle", routeLinkData)">Link</a>"
I was reading the ASP.NET MVC Best Practices article by Rashid, and got stuck in his description of creating UrlHelper extensions. Doing this is easy enough, and I've adopted the practice into all of my projects. I noticed, however, that Rashid used Url.Content to generate the url for the home page, and Url.RouteUrl for all the other urls. Why is this? What is the difference between the two?
The link to the blog post is here: http://weblogs.asp.net/rashid/archive/2009/04/01/asp-net-mvc-best-practices-part-1.aspx
I've used Html.ActionLink in my Views, but I'm wondering what difference it would be if I used Url.RouteUrl instead. Does anyone have a good grasp of what makes these helpers different, and where they are best used?
to pass existing route values using the RouteUrlExpressionBuilder syntax?
I mean, having a page route, say, 'Countries/Great Britain', how can I get a hyperlink with NavigateUrl="<%$ RouteUrl: RouteName=cities,country=*current*,city=London %>" without using codebehinds?
I'm currently doing something in OrchardCMS we're using URLRewrite so that if a user comes to the site from site.com or from site.com/orchard, they get the site.com/orchard page. One of the problems is that it's throwing the urls in the menu because it's using urlHelper.RouteUrl which uses the wrong context and then produces a url like site.com/page1 rather than site.com/orchard/page1. Is there either a way to tell urlHelper.RouteUrl to start from a different page than the current one, or to get the function to return the full path?
I want to disable certain elements in the markup in the aspx file, e.g. I don't want to have the markup pagination if there are no items to display, etc.
I'm aware that you can disable html elements using javascript, but I'd rather not do it this way since I can't guarantee that everybody who looks at my site will have a browser with javascript enabled.
The way I'd been doing it is to create a literal control, and in the codebehind file on page load, I'd set the text to either the empty string or the actual html markup that I wanted.
However, this has problems in that I need to recompile and rerun the website everytime I want to change the markup, rather than just make my changes in the aspx file and refresh the page.
I know that some controls, such as repeaters, etc, have templates which can be set by loading in the code from another aspx/ascx file, but I don't know if this is possible with literal controls.
I'm quite new to web development, but I figure this is something that must come up quite a lot so I didn't know if there was a standard way which is agreed to be the best way to do this kind of thing.
I have a Master Page as well as a standard Web Form aspx file. What if I wanted to dynamically modify the complete HTML markup in an aspx file (perhaps based on a conditional statement - perhaps in a specific content place holder), how would I go about doing this? Sorry I'm coming from a PHP background so this is why I'm asking such a simple question.
I have added a favicon to my site but it will not appear. I have the following two lines in the master page markup:
[Code]....
When the first page that uses the master page is rendered in the browser, these links are:
[Code]....
This is as I would expect yet the favicon does not appear. It appears fine on any basic html pages but simply won't on any pages that are based on the master page.
I'm trying to add some basic HTML markup to my code-behind, just a H1 and a few breaks separating strings in the message.Body, but can't seem to get it going without errors.
[Code]....
Probably a straightforward thing, or not intended usage at all,
I'm using an ImageButton inside a repeater with an ItemCommand. The repeater is used as a trigger to an UpdatePanel. The XHTML generated puts an 'ItemCommand' attribute in the <input> element corresponding to the ImageButton. This causes XHTML validation (using the W3C validator) to fail, because ItemCommand isn't a valid attribute for input.
I've Googled and found nothing about this, and the MSDN page assures me that asp.net generates perfect XHTML.
In my master page I tried to do the following: <asp:HyperLink ID="asdf" runat="server" NavigateUrl='<%= GetRouteUrl("about-route", new {}) %>'>Test</asdf> I got a compiler error: Server tags cannot contain <% ... %> constructs. What is the proper way to create a route URL in a server control in Web Forms? I also need to include it in the following:
This type of thing. when I first came across it I loved it, i'm using it again today but not quite so simply. I have a number of extra things I would like to achieve.
Apply formatting to the value. Like Text='<%# string.Format(XPath("FACEVALUE"), "{0:c}") %>'> <asp:LinkButton ID="lnkBook" runat="server" PostBackUrl='/THEATRE/' + XPath("FACEVALUE")>Book</asp:LinkButton>
For option number 2 the URL is not as I would expect, and for number 1 I cannot get the syntax correct if it's even possible.
I have not been able to find something suitable in google. Hopefully what I am trying to achieve is obvious from the example :)
I have an assembly called like X.Common.DLL. There is some resources files for multilanguage app. Let's say it Language.resx Language.en-US.resx....etc.... I have a web application which contains this above dll as reference... So how can I use this resources file in my web applications markup side?
Text="<%$ Resources:Class, ResourceKey %>" is not valid because of "Class" name is in another assembly...
Ive got problem with intellisense in markup for example:
When I type
<dxwgv:ASPxGridView ID="grid" runat="server"> <Columns> < -- here I hit ctrl + space and only normla html tags are shown: a, abbr ... -- But I would like to have available columns instead :/ </Columns> </ dxwgv:ASPxGridView>
I have a DropDownList in a template column of a GridView control. The GridView is bound to a list of objects. Each object has a property of type int which corresponds to a value in one of the DropDownLists ListItems. I could set the selected item programatically by adding a DataBind event to the drop down, but I'm wondering if there's a way to set the selected item by using a code block in the aspx markup.