Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC how can i post a form without using a model

I would like to know how i could sumbit a form in mvc 4 without using a model binding to the view.

can some one please demontrate how? and how can i use that form in the controller?

like image 626
kayze Avatar asked Dec 15 '22 19:12

kayze


1 Answers

It is very easy to use a form without any sort of Model binding.

Simple set up your for using either @using(Html.BeginForm()){ ... } or plain html.

<form id="myForm" action="/ControllerName/ActionName" method="Post">

    <input type="text" name="foo" value="FOOOO" />
    <input type="text" name="bar" value="Baaaar" />
    <button type="submit">Submit</button>

</form>

When you post this to the ActionResult, your action result just needs to be set up to accept a string value named foo and one named bar

[HttpPost]
public ActionResult ActionName(string foo, string bar){
    // your code here
    return View();
}
like image 181
Tim B James Avatar answered Jan 12 '23 04:01

Tim B James