You can use the parameters directly; parameters will automatically be parsed and displayed on the correct type. The names of the parameters in the method must match the names of the parameters that are submitted from your form.
[AcceptVerbs(HttpVerbs.Post)] public ActionResult AddNewLink(string url, string description, string tagsString) { string[] tags = tagsString.Replace(" ","").Split(','); linkRepository.AddLink(url, description, tags); }
As a rule, this works with more complex objects, if its properties can be set, and while your form keys are in the format objectName.PropertyName. If you need something more advanced, you should learn about model bindings .
public class MyObject { public int Id {get; set;} public string Text {get; set;} } [AcceptVerbs(HttpVerbs.Post)] public ActionResult AddNewLink(MyObject obj) { string[] tags = obj.Text.Replace(" ","").Split(','); linkRepository.AddLink(url, description, tags); }
Blake pettersson
source share