Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Creating views using controllers in MVC

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 51
    Comment on it

    In MVC while creating project your first task is to create a controller where code behind is defined.

     public class HomeController : Controller
        {
            public ActionResult Index()
            {
                return View();
            }
    
            public ActionResult About()
            {
                ViewBag.Message = "Your application description page.";
    
                return View();
            }
            
            public ActionResult Contact()
            {
                ViewBag.Message = "Your contact page.";
    
                return View();
            }
        }

    This can create any number of methods which returns ActionResult always

    After creating this you need to create a view related to it by right clicking on it

    Add view

    Select your model class

     

    View will be created

    @model MVC_Demo.Models.EmployeeModel
    
    @{
        ViewBag.Title = "Home";
    }
    
    <h2>Home</h2>
    
    <div>
        <h4>EmployeeModel</h4>
        <hr />
        <dl class="dl-horizontal">
            <dt>
                @Html.DisplayNameFor(model => model.FirstName)
            </dt>
    
            <dd>
                @Html.DisplayFor(model => model.FirstName)
            </dd>
    
            <dt>
                @Html.DisplayNameFor(model => model.MiddleName)
            </dt>
    
            <dd>
                @Html.DisplayFor(model => model.MiddleName)
            </dd>
    
            <dt>
                @Html.DisplayNameFor(model => model.LastName)
            </dt>
    
            <dd>
                @Html.DisplayFor(model => model.LastName)
            </dd>
    
            <dt>
                @Html.DisplayNameFor(model => model.PhoneNo)
            </dt>
    
            <dd>
                @Html.DisplayFor(model => model.PhoneNo)
            </dd>
    
            <dt>
                @Html.DisplayNameFor(model => model.Address)
            </dt>
    
            <dd>
                @Html.DisplayFor(model => model.Address)
            </dd>
    
            <dt>
                @Html.DisplayNameFor(model => model.errormsg)
            </dt>
    
            <dd>
                @Html.DisplayFor(model => model.errormsg)
            </dd>
    
        </dl>
    </div>
    <p>
        @Html.ActionLink("Edit", "Edit", new { /* id = Model.PrimaryKey */ }) |
        @Html.ActionLink("Back to List", "Index")
    </p>
    

     

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: