views:

487

answers:

1

I am working on chart project in asp.net mvc so any one can kindly tell me how to retrive values from the text boxes to apply to the series of the chart?

+2  A: 

MVC automatically maps form values to Action parameters for you by name. String and primitive value types are easy.

[HttpPost]
public ActionResult AttemptLogin( string username, string password )

We can also use entity types as action parameters. In this case the default ModelBinder is used, and it tries to bind any post data that matches the patters of "parameterName.PropertyName". If my form contains a field named "user.FirstName", my user object will have that property set.

[HttpPost]
public ActionResult Save( User user )

Custom ModelBinders and BindAttribute provide for additional flexibility in model binding.

// do not let MVC bind these properties
[Bind(Exclude="Created, Modified")]
public class User

I could have a custom binder for User, for use in a change my own details screen. This might only FirstName, LastName and Email properties.

[HttpPost]
public ActionResult ChangeDetails( guid Id, [ModelBinder(typeof(UserChangeDetailsBinder))] User user )

If I had a custom binder that should be used in place of the default one, it would be registered in global.asax.cs.

ModelBinders.Binders[typeof(User)] = new UserBinder();

You can also read form values from Request["fieldname"].

Lachlan Roche
In MVC2 instead `AcceptVerbs("POST")` we use `HttpPost` attribute.
Robert Koritnik
thank you so much
mary