html.actionlink

MVC3 Html.ActionLink Post

拟墨画扇 提交于 2019-11-28 03:39:34
问题 I have an MVC3 C#.NET web app and need to call a view using Html.ActionLink. I can't tell from the documentation if I can specify the POST or GET. Below is my HTML, is there a way to specify GET or POST? @Html.ActionLink("Create New", "Edit", "Subtask", new {Id = ViewBag.Id, Command="CreateHourEntry"}, null) 回答1: If you want a post use Ajax.ActionLink but be aware it's an Ajax post. You could easily use jquery to cause your existing link to cause a form post but this functionality is not

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

ASP.NET MVC 4 Passing Object Variable Through ActionLink

心不动则不痛 提交于 2019-11-27 15:39:26
I have an ASP.NET MVC 4 application. There is a razor view in my application that works with List type as a model. @model List<MeetingLog.Models.UserModel> @{ Layout = null; } . . . I am iterating through Model variable like this: @foreach (var item in Model) { <tr> <td> @item.Name </td> <td> @item.Surname </td> <td> @Html.ActionLink("Click", "SavePerson", "Meeting", new {model = item, type = "coordinator"}, null) @Html.ActionLink("Click", "SavePerson", "Meeting", new {model = item, type = "participant"}, null) </td> </tr> } I need to pass two variables to SavePerson action with action links.

System.Web.Mvc.HtmlHelper' does not contain a definition for 'ActionLink'

落爺英雄遲暮 提交于 2019-11-27 15:37:44
问题 I would like to use custom @Html.ActionLink I am trying to use the following code:- public static class LinkExtensions { public static MvcHtmlString MyActionLink( this HtmlHelper htmlHelper, string linkText, string action, string controller) { var currentAction = htmlHelper.ViewContext.RouteData.GetRequiredString("action"); var currentController = mlHelper.ViewContext.RouteData.GetRequiredString("controller"); if (action == currentAction && controller == currentController) { var anchor = new

How to pass Area in Url.Action?

孤街醉人 提交于 2019-11-27 11:26:39
问题 The problem in Html.ActionLink() is that you can't add additional html content inside the tag that it generates. For example, if you want to add an icon besides the text like: <a href="/Admin/Users"><i class="fa fa-users"></i> Go to Users</a> Using Html.ActionLink(), you can only generate: <a href="/Admin/Users">Go to Users</a> So, to resolve this, you can use Url.Action() to generate only the URL inside the tag like: // Here, Url.Action could not generate the URL "/admin/users". So this

Passing parameter to controller action from a Html.ActionLink

我们两清 提交于 2019-11-27 08:35:36
Is there anything wrong with this html? I want to have a link in the masterpage to navigate to "CreateParts" view. I have action 'CreateParts' which have a parameter parentPartId in the controller 'PartList'. <li id="taskAdminPartCreate" runat="server"> <%= Html.ActionLink("Create New Part", "CreateParts", "PartList", new { parentPartId = 0 })%></li> My controller action is like public ActionResult CreateParts(int parentPartId) { HSPartList objHSPart = new HSPartList(); objHSPart.Id = parentPartId; return View(objHSPart); } When I click on 'Create New Part' in the menu in SiteMaster, I get

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

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 4 Passing Object Variable Through ActionLink

南笙酒味 提交于 2019-11-26 17:18:41
问题 I have an ASP.NET MVC 4 application. There is a razor view in my application that works with List type as a model. @model List<MeetingLog.Models.UserModel> @{ Layout = null; } . . . I am iterating through Model variable like this: @foreach (var item in Model) { <tr> <td> @item.Name </td> <td> @item.Surname </td> <td> @Html.ActionLink("Click", "SavePerson", "Meeting", new {model = item, type = "coordinator"}, null) @Html.ActionLink("Click", "SavePerson", "Meeting", new {model = item, type =

Passing parameter to controller action from a Html.ActionLink

泪湿孤枕 提交于 2019-11-26 14:12:02
问题 Is there anything wrong with this html? I want to have a link in the masterpage to navigate to "CreateParts" view. I have action 'CreateParts' which have a parameter parentPartId in the controller 'PartList'. <li id="taskAdminPartCreate" runat="server"> <%= Html.ActionLink("Create New Part", "CreateParts", "PartList", new { parentPartId = 0 })%></li> My controller action is like public ActionResult CreateParts(int parentPartId) { HSPartList objHSPart = new HSPartList(); objHSPart.Id =