I have a textbox input and some radio buttons. For example my textbox input HTML looks like that:
<input type="text" name="IP" id="IP" />
Once user clicks a button on a web page I want to pass data to my controller:
<input type="button" name="Add" value="@Resource.ButtonTitleAdd" onclick="location.href='@Url.Action("Add", "Configure", new { ipValue =@[ValueOfTextBox], TypeId = 1 })'"/>
Maybe it is trivial but my problem is that I do not know how to get textbox value and pass it through to the controller. How can I read the textbox value and pass it to the controller through ipValue=@[ValueOfTextBox]
?
Simple ASP.NET MVC subscription form with email textbox would be implemented like that:
Model
The data from the form is mapped to this model
View
View name should match controller method name.
Controller
Controller is responsible for request processing and returning proper response view.
Here is my project structure. Please notice, "Home" views folder matches HomeController name.
Another way by using ajax method:
View:
Controller:
Try This.
View:
Controller:
If you can use model class
you can do it so simple:
First: For Example in Models you have User.cs with this implementation
We are passing the empty model to user – This model would be filled with user’s data when he submits the form like this
When you return the View by empty User as model, it maps with the structure of the form that you implemented. We have this on HTML side:
So on button submit you will use it like this
You may use jQuery: