actionlink

How to send data through actionlink in asp.net?

瘦欲@ 提交于 2021-02-07 19:41:34
问题 In the application that I am trying to make, I have a menu in my view as below: <ul id="menu"> <li>@Html.ActionLink("Create Project", "Display", "CreateDisplay")</li> <li>@Html.ActionLink("Open", "About", "Home")</li> </ul> where CreateDisplay is the name of a controller and Display is a method in that controller which will call another view. But, I want the Display method to accept certain parameters like username of the person. In the current view, I have obtained the username as @ViewData[

@Html.ActionLink and @Html.DisplayFor at the same time (not right, but it describes what I want to do)

北战南征 提交于 2021-02-06 14:59:37
问题 I have the following table located in a view within a controller named Student (/Student/Details/1): @foreach (var item in Model.Enrollments) { <tr> <td> @Html.DisplayFor(modelItem => item.Course.Title) </td> <td> @Html.DisplayFor(modelItem => item.Grade) </td> </tr> } I would like to make each table definition into a link that takes me to a view within a controller named Course (/Course/Details/1). I have tried things along the lines of: @Html.ActionLink(Html.DisplayFor(modelItem => item

URL-encode parameters in ActionLink?

谁都会走 提交于 2021-01-28 00:46:34
问题 I have the following route registered; routes.MapRoute( "LocationsByArea", "Locations/{system}/{storage}/{area}", new { controller = "StorageLocation", action = "Index" }, null ); ...and the following code in my view; <%= Html.ActionLink("Platser", "Index", "StorageLocation", new { system = Model.System, storage = Model.Storage, area = item.Name }, null)%> My problem is when the "area = item.Name" contains a colon, e.g. "Area 4:1". If I click the rendered link I get HTTP-error 400, Bad reqest

How do you link to an action that takes an array as a parameter (RedirectToAction and/or ActionLink)?

爷,独闯天下 提交于 2021-01-02 08:11:14
问题 I have an action defined like so: public ActionResult Foo(int[] bar) { ... } Url's like this will work as expected: .../Controller/Foo?bar=1&bar=3&bar=5 I have another action that does some work and then redirects to the Foo action above for some computed values of bar . Is there a simple way of specifying the route values with RedirectToAction or ActionLink so that the url's get generated like the above example? These don't seem to work: return RedirectToAction("Foo", new { bar = new[] { 1,

MapPageRoute Breaks ActionLinks in Integrated MVC/WebForms App

こ雲淡風輕ζ 提交于 2020-06-23 08:56:50
问题 I have an existing Web application that was developed in ASP.NET 4.0. I want to add MVC functionality to the app, so I've integrated MVC into the app as per Scott Hanselman's article Integrating ASP.NET MVC 3 into existing upgraded ASP.NET 4 Web Forms applications. Because MVC routing is greedy, I added the following code to my Global.asa so that an empty URL will go to my Default.aspx: routes.MapPageRoute("WebFormsDefault", "", "~/Default.aspx"); The problem now is that ActionLinks and

Passing a parameter to Html.ActionLink when the model is IEnumerable<T>

為{幸葍}努か 提交于 2020-02-05 10:04:09
问题 I really hope someone can help me with this somewhat simple thing I am trying to do. I am very new to MVC and am still trying to get my head around it! I have a controller called Submission that gets passed a company id so I can keep track of which company we are working in. http://myurl/Submission/Index/1 The code for this view: @model IEnumerable<Reports.Models.Submission> @{ ViewBag.Title = "Index"; } <p>@Html.ActionLink("Create New", "Create")</p> @foreach (var item in Model) { <p>@Html

How Can I Stop ASP.Net MVC Html.ActionLink From Using Existing Route Values?

夙愿已清 提交于 2020-01-09 13:05:28
问题 The website I'm working on has some fairly complicated routing structures and we're experiencing some difficulties working with the routing engine to build URLs the way we need them to be built. We have a search results page that uses RegEx based pattern matching to group several variables into a single route segment (i.e. "www.host.com/{structuralParameters}" can be the following: "www.host.com/variableA-variableB-variableC" - where variables A through C are all optional). This is working

MVC ActionLink add all (optional) parameters from current url

谁说胖子不能爱 提交于 2020-01-09 04:24:06
问题 The very famous ActionLink : <%: Html.ActionLink("Back to List", "Index")%> Now, this link is in my Details view. The Index view is a search page. The URL of that looks like this: http://localhost:50152/2011-2012/Instelling/Details/76?gemeente=Dendermonde&postcode=92**&gebruikerscode=VVKSO114421&dossiernr=114421%20&organisatie=CLB As you can see, quite the amount of parameters. Obviously I want to keep all these parameters when I return to the Index page, so I need to add them in the

passing multiple parameters in @html.actionlink()

蹲街弑〆低调 提交于 2020-01-06 04:03:42
问题 I'm using actionlink to pass parameter "code" to controller for an item and get details for that item on new view (actually, it's controller that calls 3 partial views) I also need to pass parameter "description" but that's just an value that need to be shown as on new view and has no use in controller (i'm using "code" to filter database records). @foreach (var item in Model.MyModel) { <tr> <td> @Html.ActionLink(item.code, "Index", "ControlerName", new { pos = item.code.ToString(), desc =

ASP.NET MVC : capture result of download prompt

谁说胖子不能爱 提交于 2020-01-05 04:23:15
问题 I have a bit of code that makes a file available and prompts user to open/download/cancel . I would like to take an action if the file is opened or downloaded , but not if canceled . This is the download line, from the controller : return File(fileAsBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName); I guess my question is, how do I capture a return value from this action? Would I see the result in the controller or in the view that calls it? I'm a struggling newbie. Don't