Postback handling options in ASP.NET MVC
I am currently handling callbacks in ASP.NET MVC - this is to capture input variables using:
string username = "";
if (null != Request["username"])
username = Request["username"].ToString();
Then I would run a regex on the variable to see if it is valid.
Is there any other way to do this?
+1
a source to share
2 answers
ASP.NET MVC automatically maps Request-To-Object through ModelBinders . An older article is here in the "Improving Post Forms and Models" section and a video here .
+1
a source to share
You can handle form inputs in your action like this:
public ActionResult Create(string username)
{
// use
}
but you need to set your route:
routes.MapRoute(
"Default", // Route name
"Create/{username}", // URL with parameters
new { controller = "YourController", action = "Create", username = "" } // Parameter defaults
);
Or you can use ModelBinders
+1
user434917
a source
to share