HTML.BeginForm

(ASP.NET MVC)


Hi,
In this article i am discussing about the Html.Beginform in asp.net mvc.

View:-
@using(Html.BeginForm("Index","Home",FormMethod.Post))
{

@Html.LabelFor(s=>s.StartDate,date.ToString("yyyy/MM/dd"))

<br />
<br />
@Html.TextBoxFor(s=>s.StartDate,new { @Value = date.ToString("yyyy/MM/dd") } )
<br />

<input type="submit"  value="Submit" />
}


Controller Action Method:-

[HttpPost] //this is invoked while submiting the form
        public ActionResult Index(DateviewModel model)
        {
            try
            {
                DateTime dt = model.StartDate;

                string fmteddt = dt.ToString("yyyy/MM/dd");

                DateviewModel models = new DateviewModel();

                models.StartDate = DateTime.Now;

                return View(models);

            }
            catch (Exception)
            { }

            return null;
        }


Image

Ratings


Average Rating: 0.00 by 0 users
Giri Prasad
7/2/2013
7/2/2013
Download PDF

Comments