Thursday, September 10, 2015

View to Model

To get the value from view page to model
 use the keyword name  in the textbox or any html controls like this
name="comment"

           
< input type="text" class="input-medium" id="website" name="website" data-val="true" data-val-required="*">

< textarea class="input-medium" id="comment" rows="3" name="comment" data-val="true" data-val-required="*">< /textarea>
namespace TestWebProject.Models
{
    public class ContactModel
    {
        public string Name { get; set; }
        public string Email { get; set; }
        public string Website { get; set; }
        public string Comment { get; set; }
    }
}
To connect to controller add the form method as Post
                   < form class="form-horizontal" method="post" >

In controller it will take automatically
        [HttpPost]
        public ActionResult Contact(ContactModel model)

No comments:

Post a Comment