0

How can I pass values back from a text box or dropdownlist or any control from a razor view back to an mvc3 controller? These values are not strongly bound so I don't have a model to bind these values to?

1 Answer 1

2

This will work:

public ActionResult SubmitAction(FormCollection collection) {
     string formValue = collection["formValue"];
}

Edit:

 public ActionResult SubmitAction(ModelName model, string field1, int field2) {

}
Sign up to request clarification or add additional context in comments.

5 Comments

Hi, thanks for the reply! So "formvalue" is the name of the control on the form (i.e. the textbox/input id?)? Is there another way to do this by saving back to a ViewBag within razor then the Viewbag can be accessed via the HttpPost Public ActionResult MethodNameHere(ModelName model) ? ? ?
Maybe I misunderstood the original question, you have some strongly bound fields and some not? If so, the above edit I think works too.
Yes, that is correct...some values will be coming in from thew view as bound to controls and the model and other values will be coming in from textboxes and dropdownlists that are not strongly bound to a model/control.
Great thanks! QQ: How can I get the values from razor into field1 and field2 (to get back and access it via the actionresult)?
It's been a while since I did it that way so it's either the FormCollection again or if that doesn't work, you can manually assign them to ViewBag variables and update the input/select boxes to use the ViewBag variable. For the select list, you'll need to do an if comparison.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.