Shalvin Interests

Tuesday, February 11, 2014

Asp .Net MVC HttpPost and BeginForm Html Helpers


public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
        
     [HttpPost]
        public ActionResult Index(FormCollection frm)
        {
         string strName = Request.Form["Name"];
         ViewBag.Name = strName;
         return View();
        }
    }

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>
@ViewBag.Name

@using (Html.BeginForm())
{
    @Html.Label("Name")
    @Html.TextBox("Name")

    <br />
    <input type ="submit" />

}

No comments:

Post a Comment