0

I have a nice HTML form that I want to use in a ASP.NET MVC application.

I created a method in controller to get the data via Formcollection and put it into database.

So far so good.

All the tutorials I see work the other way round, i.e. they create the form from the controller.

But I want to get data from html form. How can it be done?

Say I have this form:

<form class="form-horizontal">
<fieldset>

<!-- Form Name -->
<legend>Form Name</legend>

<!-- Multiple Radios -->
<div class="form-group">
  <label class="col-md-4 control-label" for="radios">Multiple Radios</label>
  <div class="col-md-4">
  <div class="radio">
    <label for="radios-0">
      <input type="radio" name="radios" id="radios-0" value="1" checked="checked">
      Option one
    </label>
    </div>
  <div class="radio">
    <label for="radios-1">
      <input type="radio" name="radios" id="radios-1" value="2">
      Option two
    </label>
    </div>
  </div>
</div>

<!-- Textarea -->
<div class="form-group">
  <label class="col-md-4 control-label" for="textarea">Text Area</label>
  <div class="col-md-4">                     
    <textarea class="form-control" id="textarea" name="textarea">default text</textarea>
  </div>
</div>

</fieldset>
</form>

I want to take the data entered by the user (I want to modify the form such that I can access it from the controller) and put it into database, how can it be accomplished by first passing the data into the controller method?

4
  • what you mean from html form? Is there any other forms? Commented Nov 1, 2017 at 13:32
  • set to the form action attribute value to an action method in your controller and you can read the submitted values there. Read about model binding Commented Nov 1, 2017 at 13:33
  • @Shyju any simple code example? Commented Nov 1, 2017 at 13:55
  • See the duplicate ASP.Net MVC How to pass data from view to controller Commented Nov 1, 2017 at 13:58

1 Answer 1

2

should not you have an 'action' which link to your controller first?

then use Request.Form["element_name"] to get the value.

You may refer to this site.

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

1 Comment

Although I upvoted...I wasn't asking this.. my form isn't like what you linked to...i have a html form...just html

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.