ActionLink htmlAttributes with hyphens

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 replace the underscore with a dash in the emitted HTML): @Html.ActionLink(“Edit”, “edit”, “markets”, new { id … Read more

How do I redirect a user when a button is clicked?

It depends on what you mean by button. If it is a link: <%= Html.ActionLink(“some text”, “actionName”, “controllerName”) %> For posting you could use a form: <% using(Html.BeginForm(“actionName”, “controllerName”)) { %> <input type=”submit” value=”Some text” /> <% } %> And finally if you have a button: <input type=”button” value=”Some text” onclick=”window.location.href=”https://stackoverflow.com/questions/3168577/<%= Url.Action(“actionName”, “controllerName”) %>”;” />

ASP.NET MVC Ajax.ActionLink with Image

From Stephen Walthe, from his Contact manger project public static class ImageActionLinkHelper { public static string ImageActionLink(this AjaxHelper helper, string imageUrl, string altText, string actionName, object routeValues, AjaxOptions ajaxOptions) { var builder = new TagBuilder(“img”); builder.MergeAttribute(“src”, imageUrl); builder.MergeAttribute(“alt”, altText); var link = helper.ActionLink(“[replaceme]”, actionName, routeValues, ajaxOptions); return link.Replace(“[replaceme]”, builder.ToString(TagRenderMode.SelfClosing)); } } You can now type … Read more

How to pass Area in Url.Action?

You can use this Url.Action(“actionName”, “controllerName”, new { Area = “areaName” }); Also don’t forget to add the namespace of the controller to avoid a conflict between the admin area controller names and the site controller names. Something like this public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( “Admin_default”, “Admin/{controller}/{action}/{id}”, new { action = “Index”, id … Read more

ActionLink htmlAttributes

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 replace the underscore with a dash in the emitted HTML): @Html.ActionLink(“Edit”, “edit”, “markets”, new { id … Read more