.net MVC Routing To Controller With Optional Parameters
Apr 9, 2010
I have a controller method that is called with many different combinations of URL's. To overcome issue i am using optional parameters.here is my controller method signature...public ActionResult localMembersSearch(string Gender, string calling, [Optional]string Region, [Optional]string County, [Optional]string Town, [Optional]string queryvalues)the first two parameters are not optional but always expect
I want to add optional parameters in my routing table.For example I would like the users to browse a product catalog like this:http://www.domain.com/browse/by-category/electronics/1,2,3 etc
I've already implemented URL routing in my app but there are cases where I may or may not get a paramter. In particular, I'm trying to come up with a good way to handle multi-language support. For example, if my regular URL is /SomeCategory/Friendly-Topic-URL, I want to have an optional language selector at the end but I'd like to be optional. So, if I get /SomeCategory/Friendly-Topic-URL/es, that should bring up the topic in Spanish but if get nothing, that should bring up English.
I'm trying to implement a search function on an incident logging page that is working fine. Currently I am only able to search against one criteria at a time, using the following route:
I'm starting a port of an existing ASP.NET Web Forms CMS to ASP.NET MVC and want to get the routing right from the start.Note: it isn't important to have the exact same URL structure.I think this answer is close to what I'm looking for but would like some additional input should anyone have it.
I would like to have two different welcome pages for a site.How could I handle this? I've looked at routing but I'm not sure if global.asax.cs is the correct place to place this into.
www.mycompany.com should display generic information. Displaying view Home/Default.aspx www.mycompany.com?id=1 should display welcome customer x. Displaying view Home/Welcome.aspx
I have the following scenario: my website displays articles (inputted by an admin. like a blog).So to view an article, the user is referred to Home/Articles/{article ID}.However, the user selects which article to view from within the Articles.aspx view itself, using a jsTree list.So I what I need to do is to be able to differentiate between two cases: the user is accessing a specific article, or he is simply trying to access the "main" articles page. I tried setting the "Articles" controller parameter as optional (int? id), but then I am having problems "using" the id value inside the controller.
I want to create a method with optional parameters in my wcf service. I am doing it like this
[Code]....
When I try to use it in my client application and try to pass the values only for first two parameters it gives me an error that"Argument not sepecified for parameter Status"
I'm using the iis7 URL Rewrite module and it's working fine, except for two things. Being new to this, I might be missing something obvious.
1) My URL gets converted from www.mysite.com/search.aspx?fName=John&sName=Smith to www.mysite.com/John/Smith. This works fine, but if I add a trailing / , a few images on the site disappear, wheras a few don't. (They're all in the same location). However, the search results are fine.
2) Is it possible to make cerain querystrings optional? Server side, this is implemented (i.e. if nothing is entered, then assume a default value). But how would this work with the URL rewrite module? e.g. www.mysite.com/John would search for John and use a default value for the sName parameter.
Basically, my question is: how do I specify optional parameters to a WebMethod when providing JSON data?
I know I can reduce the parameters down to just the required values, and then use HttpContext.Request.Params to read the values of optional paramaters, but I would have thought the way I have tried here should have worked.
EDIT
The XMLHttpRequest.responseText value for the error is:
Invalid JSON primitive: staffcode.
This is throwing me even more off the scent of the problem :(
I have a GridView bound to an DataSource query with parameters tied to form controls.What is the standard / best-practices way to handle optional query parameters?
I'm creating a webpage with serveral web controls to set search parameters for querying an SQL table. My plan is to use a TableAdapter to hold the query. If the user decides not to use one, several, or any of the web controls to filter their search, I want the SELECT to execute without complaining that it doesn't have parameter values. Should my SQL query look like
I have a data grid with a lot of information on it - to easily filter the data, I would like to be able to pass parameters to it. My problem is that I do not want the parameters to be required. So if I just put 1 or 2 of them in the query string, I would like for it to return all of the data related to those two parameters.I am using a data grid & stored procedures:My Stored Procedure looks like this:
Basically I have RegisterModel2 that has a Person class. My requirement is that Phone Number and Address are not required for registration. But if they try to enter a Phone number of Address then it should validate it. Problem is that it is always stating that the child fields of Phone (area code, number) and child fields of Address (street1,city,etc) are required. Is there a way to annotate in the RegisterModel that a parent class is not Required but if any data in a child element is given then and only then should the child elements be validated?
My Person EDM class has a nullable 0.1 -> 0.1 navigation property to Phone and Address.Here is the person class
[MetadataType(typeof(Person_Validation))] public partial class Person { }
public class Person_Validation [code]....
The Person EntityObject has an optional/nullable Navigation Property to the Phone Object.
The Phone object has these annotations,[Code]....
I have RegisterModel defined as follows: [Code]....
My View looks like this: [Code]....
And here is my Controller Action it is posting to: [Code]....
I'm trying to have a parameter as optional i.e. /Category/{ProductName}/{ProductOption} where ProductOption is optional. How do I handle this in web forms 4? Here's what my code looks like now:
How would I create the link in my grid using the action link?
EDIT:
The grid above is on my Index view in my Home direcotry. So on this grid I need to concatenate the link to display as above. I'm struggling to create this link on my Index view. It's not concatenating correctly. Currently I have this:
I consider the following an error, and not a feature:
When posting a request, any parameters are held in the HttpContext.Request.Form as key/value pairs. This is perfectly fine for the recipient of the request. Unfortunately, however, further down the chain these values still exist and take precedent in binding over new parameters created during processing.
This is obvious in the RenderAction scenario. If a new parameter is created in a view and passed through RenderAction, if the parameter has the same name as one of the initial request parameters (or a form field for that matter), then MVC Binding will bind the initial request form value to the Action being called, and not the new parameter being defined in the RenderAction call. What's even more frustrating, is there is no easy way to override the initial form values.
It really does not make sense that a value defined in one context, should live throughout the entire processing context... at least without the developer being able to determine it should remain. At a minimum, any new parameter defined in the process with the same name should either a) be received as a parameter and not a form value; or b) override the form value.
I would like to be able to type in a URL like [URL] arrive at a Details Page which parsed the "M" and the "123" from the query string and used them as params to query a Table in my Database. I've been reading my @$$ off and I can't find anything close :>
I need to use routing with parameters in my ASP.NET application.
public class Global : System.Web.HttpApplication { void Application_Start(object sender, EventArgs e)
Then, by navigating to "/Profile" I want to get on Page_Load method Request.Params["Id"] as null and by navigating to "/Profile/1", Request.Params["Id"] as "1".
How can I pass two querysting parameters in URL routing using ASP.NET 4.0? I have gone through many articles, but everywhere it shows only one parameter. I'd like the display URL to be: [URL] The first parameter is ID: 1 The second is Name: This is my first report I am trying following route, but it is not working
routes.MapPageRoute( "MarketReports", // Route name "Reports/{*i}-{*n}", // Route URL "~/pageControl2.aspx" // Web page to handle route );