Wednesday, 7 January 2015

How to pass data from View to Controller in MVC4 Razor using C#/VB.NET

Hi friends,in this article I will explain about How to pass data from View to Controller in MVC4 Razor using C#/VB.NET.
I already explained in the previous articles about MVC4 Razor: How to compare password and confirm password in ASP.NET MVC4 RazorHow to create a DropDownList field for MVC4 Razor view? and How to Update multiple rows at once Using MVC 4 Razor and Entity Framework

    public ActionResult Register()
            var obj=new Home();
            return View(obj);
        public ActionResult Register(Home obj1)
            obj1.Username = Request.Form["txtUsername"].ToString();
            obj1.Password = Request.Form["txtpwd"].ToString();
            int retval = obj1.Register();
            return View("Register", obj1);

@model MvcNew.Models.Home

    ViewBag.Title = "Register";


@using (Html.BeginForm()) {

        <div class="editor-label">
            @Html.LabelFor(model => model.Username)
        <div class="editor-field">
            @Html.ValidationMessageFor(model => model.Username)

        <div class="editor-label">
            @Html.LabelFor(model => model.Password)
        <div class="editor-field">
            @Html.ValidationMessageFor(model => model.Password)

            <input type="submit" value="Create"  />

    @Html.ActionLink("Back to List", "Index")

@section Scripts {

1 comment:

  1. well this was very nice article and very good information for ASP.NET learners i was really satisfied see this information we also provide ASP.NET Online Training


© 2012-2018 All Rights Reserved.
The content is copyrighted to Kishore and may not be reproduced on other websites without permission from the owner.