2

I want to pass additional data back to the MVC controller, without changing my ViewModel.

Is there a way to do this without using the formcollection?

For example, something like:

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Edit(ViewModel item, formvalue a)
    {
    }

1 Answer 1

2

You're on the right track. You'll need to know the name/key of the form item you want bound. For example, if it's <input type="text" name="MyInput" />, the action can be:

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(ViewModel item, string myInput)
{
}

And another idea, you could pass in the entire form collection and then access it:

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(ViewModel item, FormCollection form)
{
    var myInput = form["MyInput"];
}
Sign up to request clarification or add additional context in comments.

Comments

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.