Posts Tagged ‘MVC’
Saturday, May 7th, 2011
To add htmlattributes to a ActionLink might be needed for instance for the layout of the page.
@Html.ActionLink("Link text", "action", "Controller", null, new {style="float:left"})
//Adding a css class (need the @sign as class is a keyword for the compiler). It is also possible to use a Capitol C in Class but then it fails some validations.
@Html.ActionLink("Link text", "action", "Controller", null, new {@class="myCssClassName"})
//the syntax for the Html.ActionLink (used in this example is)
public static MvcHtmlString ActionLink(
string linkText,
string actionName,
string controllerName,
RouteValueDictionary routeValues,
IDictionary<string, Object> htmlAttributes
) |
Tags: ActionLink, asp.net, C#, Html helper, Html.ActionLink, MVC, MVC3
Posted in ASP.NET C#, MVC3 | No Comments »
Saturday, April 30th, 2011
Using routevalues you can tell the html helper what area you want to create a action link to.
//create a link that will go to AreaName
Html.ActionLink("Link Text", "ActionName", "ControllerName", new { Area = "AreaName" }, new{})
//Default area (= no area)
Html.ActionLink("Link Text", "ActionName", "ControllerName", new { Area = "" }, new{})
//create a link that will go to AreaName and with some htmlAttributes
Html.ActionLink("Link Text", "ActionName", "ControllerName", new { Area = "AreaName" }, new{@class="myCssClass"})
//Definition
public static MvcHtmlString ActionLink(
string linkText,
string actionName,
string controllerName,
RouteValueDictionary routeValues,
IDictionary<string, Object> htmlAttributes
) |
Tags: ActionLink, area, asp.net, C#, Html helper, Html.ActionLink, MVC, MVC3
Posted in ASP.NET C#, MVC3 | No Comments »
Saturday, April 2nd, 2011
If there is a need to get the URI that the was used to reach the controller then the Request holds that information and it can be retrieved to a URI object
public ActionResult MyAction()
{
var uri = Request.Url;
var port = uri.Port;
var absoluteUri = uri.AbsoluteUri
//... do things here
return View();
} |
Tags: asp.net, C#, MVC, MVC3, Request, System.Uri, URI
Posted in ASP.NET C#, MVC3 | 1 Comment »