ITsolutionWizard
asked on
mvc post and get
I have simple mvc project with c#. and I only want to post <input type="text" id="email" name="email">
To controller. Assume the view name is "Quote"
and I want to use same controller name - one for get, and one for post.
Can you show me in codes how it works? I am new in .net mvc.
Thanks,
To controller. Assume the view name is "Quote"
and I want to use same controller name - one for get, and one for post.
Can you show me in codes how it works? I am new in .net mvc.
Thanks,
Have you checked the official MVC site? It has many tutorials, both in video format as well as text.
ASKER
Yes I did. No one shown me how to have same controller name with different method http
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I try it and red line show up
Where are you getting a red line? Show your code!
GET may or may not have parameters. By convention, GET parameters are passed via the URL.
POST may or may not have parameter. By spec, POST parameters are passed via the body. (I believe nothing in the spec forbids URL parameters.)
In MVC, however you send parameters they come into the actions as parameters--regular old C# parameters. GETs are usually simple types; POSTs are usually complex types (i.e. classes). Keep in mind that when you're inside your action, that is C# code. As such, you have to follow C# rules. If you have two actions (i.e. methods) with the same name, then the parameter list has to vary--either in number of parameters or in data types (or both). Simply attributing two actions with HttpGet or HttpPost is not enough to let the compiler differentiate between which action to invoke. Your bound to C# rules once you're working inside the controller.
POST may or may not have parameter. By spec, POST parameters are passed via the body. (I believe nothing in the spec forbids URL parameters.)
In MVC, however you send parameters they come into the actions as parameters--regular old C# parameters. GETs are usually simple types; POSTs are usually complex types (i.e. classes). Keep in mind that when you're inside your action, that is C# code. As such, you have to follow C# rules. If you have two actions (i.e. methods) with the same name, then the parameter list has to vary--either in number of parameters or in data types (or both). Simply attributing two actions with HttpGet or HttpPost is not enough to let the compiler differentiate between which action to invoke. Your bound to C# rules once you're working inside the controller.