asp.net-mvc-routing

Hide Querystring in MVC action

醉酒当歌 提交于 2019-12-22 18:29:25
问题 I want to hide the Querystring into My controller's action. In my application scenariois something like this: 1) I have opened new action into new Window as: var check="Particular String" var url = rootUrl("Home/Preview?Docs=" + check); window.open(url, '_blank'); 2) On controller's Side I have used some code into Controller's action as: public ActionResult Preview(string Docs) { TempData["Docs"] = Docs; return RedirectToAction("UnInvoicedPreview"); } My Query:: 1) when opening new window it

MVC - Application root appears twice in url using Url.Content/Url.Action

两盒软妹~` 提交于 2019-12-22 13:10:10
问题 I have several mvc applications on the same domain, each have their own directory. mydomain.com/app1 mydomain.com/app2 etc.. When using Url.Content() and Url.Action() when at the root level, 'app1' part is repeated twice in the urls. // code used to generate the links <%= Url.Action("tetris", "Apps") %> Page Url: mydomain.com/app1/ rendered link (broken): mydomain.com /app1/app1/ Apps.aspx/tetris application root appears twice in the rendered url when at the root directory Page Url: mydomain

ASP.NET Mvc - nullable parameters and comma as separator

老子叫甜甜 提交于 2019-12-22 11:25:55
问题 How should I define route in my global.asax to be able use nullable parameters and coma as separator? I'm trying to implement routing rule for my search users page like "{Controller}/{Action},{name},{page},{status}" Full entry from the Global.asax: routes.MapRoute( "Search", "{controller}/{action},{name},{page},{status}", new { controller = "User", action = "Find", name = UrlParameter.Optional, page = UrlParameter.Optional, status = UrlParameter.Optional } ); Routine defined like above works

MVC Handler for an unknown number of optional parameters

风格不统一 提交于 2019-12-22 10:27:58
问题 I am workingon an MVC route that will take an unknown number of parameters on the end of the URL. Something like this: domain.com/category/keyword1/keyword2/.../keywordN Those keywords are values for filters we have to match. The only approach I can think of so far is UGLY... just make an ActionResult that has more parameters than I am ever likely to need: ActionResult CategoryPage(string urlValue1, string urlValue2, string urlValue3, etc...) { } This just doesn't feel right. I suppose I

Make ASP.NET MVC Route Id parameter required

僤鯓⒐⒋嵵緔 提交于 2019-12-22 09:41:02
问题 I have this route: routes.MapRoute( "PlaceDetails", "{controller}/{action}/{id}", new { controller = "Place", action = "Details", id = UrlParameter.Optional } ); This routes this fine: mysite.com/place/details/123 Making Id 123 available to the details action of the place controller - which can then lookup place '123'. However - this URL is also passed to the controller: mysite.com/place/details/ I want this to return HttpNotFound - but it sends a null Id to the controller - and requires me

How to bypass the exception multiple actions were found in ASP.NET Web API

一个人想着一个人 提交于 2019-12-22 09:13:59
问题 When trying to find solution for this below question: MVC Web Api Route with default action not working Mostly I run across the problem "multiple actions were found". If routing mechanism finds out more than one actions matched with a route, it throws out the exception 500. For example, there are two actions in ValuesController: [HttpGet] public IEnumerable<String> Active() { var result = new List<string> { "active1", "active2" }; return result; } public IEnumerable<string> Get() { return new

Web API routing and a Web API Help Page: how to avoid repeated entries

空扰寡人 提交于 2019-12-22 08:57:53
问题 I am getting repeat entries rendered in my Web API Help Page with different parents, such as these, that refer to the same method: GET api/{apiVersion}/v1/Products - Gets all products ... GET api/v1/Products - Gets all products ... I have a Web API page with some routing like this: config.Routes.MapHttpRoute ( name: "DefaultVersionApi", routeTemplate: "api/{apiVersion}/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); config.Routes.MapHttpRoute ( name: "DefaultApi",

Passing parameters to Controller ..but NOT on the URL

你。 提交于 2019-12-22 07:01:32
问题 Is there a way to pass a parameter to a controller without putting it on the URL? For example, http://www.winepassionate.com/p/19/wine-chianti-docg-la-moto has the value 19 on the URL. If you actually change that value to another, the page displays a different record even it the page name remains the same. So I would like to NOT pass the ID on the URL but still be able to pass that to the Controller. What's the recommended way to do so? 回答1: You can do a post and send it as a form parameter.

Handling MVC2 variables with hyphens in their name

五迷三道 提交于 2019-12-22 05:29:25
问题 I'm working with some third-party software that creates querystring parameters with hyphens in their names. I was taking a look at this SO question and it seems like their solution is very close to what I need but I'm too ignorant to the underlying MVC stuff to figure out how to adapt this to do what I need. Ideally, I'd like to simply replace hyphens with underscores and that would be a good enough solution. If there's a better one, then I'm interested in hearing it. An example of a URL I

How to redirect to route using custom attribute routing in MVC5

▼魔方 西西 提交于 2019-12-22 04:46:08
问题 I'm not sure if what I'm attempting to do is valid as I'm a relative newbie to the C# / ASP.NET / MVC stack. I have a controller action like this in ModelController.cs //Get [Route("{vehiclemake}/models", Name = "NiceUrlForVehicleMakeLookup")] public async Task<ActionResult> Index(string vehicleMake) { // Code removed for readaility models = await db.VehicleModels.Where(make => make.VehicleMake.Make == vehicleMake).ToListAsync(); return View(models); } and in another controller called