.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

view the data(view the Details)-using by MVC Concepts

Posted By:Daniel Bhagathsingh       Posted Date: December 19, 2013    Points: 40    Category: Visual Studio    URL: http://www.dotnetspark.com  

If we want view details from table we can use this query
 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BusinessLayer;

namespace MVCDemo14.Controllers
{
    public class StudentController : Controller
    {
        public ActionResult Index()
        {
            StudentBusinessLayer studentBusinessLayer = new StudentBusinessLayer();
            List<Student> students = studentBusinessLayer.Students.ToList();
            return View(students);
        }
        [HttpGet]
        public ActionResult Create()
        {
            return View();

        }
        [HttpGet]
        public ActionResult Details(int id)
        {
            StudentBusinessLayer studentBusinessLayer = new StudentBusinessLayer();
            Student student = studentBusinessLayer.Students.Single(stu => stu.SId == id);
            return View(student);
        }
        [HttpGet]
        public ActionResult Edit(int id)
        {
            StudentBusinessLayer studentBusinessLayer = new StudentBusinessLayer();
           Student student = studentBusinessLayer.Students.Single(stu => stu.SId == id);
           return View(student);
        }
        [HttpPost]
        [ActionName("Edit")]
        public ActionResult Edit_Post(int id)
        {
            StudentBusinessLayer studentBusinessLayer = new StudentBusinessLayer();
            Student student = studentBusinessLayer.Students.Single(x => x.SId == id);
            UpdateModel(student,new string[]{"SId" , "Age" , "Gender" , "Course" , "Departement" , "Place"});

            if (ModelState.IsValid)
            {
                
                studentBusinessLayer.SaveStudent(student);

                return RedirectToAction("Index");

            }
                return View(student);

        }
        [HttpPost]
        public ActionResult Create(FormCollection formCollection)
        {
            Student student = new Student();
            student.SId = Convert.ToInt32(formCollection["SId"]);
            student.Name = formCollection["Name"];
            student.Age = Convert.ToInt32(formCollection["Age"]);
            student.Gender = formCollection["Gender"];
            student.Course = formCollection["Course"];
            student.Departement = formCollection["Departement"];
            student.Place = formCollection["Place"];

            StudentBusinessLayer studentBusinessLayer = new StudentBusinessLayer();
            studentBusinessLayer.AddEmployee(student);

            return RedirectToAction("Index");
         
        }
        [HttpPost]
        public ActionResult Details(FormCollection formCollection)
        {
            Student student = new Student();
            student.SId = Convert.ToInt32(formCollection["SId"]);
            student.Name = formCollection["Name"];
            student.Age = Convert.ToInt32(formCollection["Age"]);
            student.Gender = formCollection["Gender"];
            student.Course = formCollection["Course"];
            student.Departement = formCollection["Departement"];
            student.Place = formCollection["Place"];

            StudentBusinessLayer studentBusinessLayer = new StudentBusinessLayer();
            studentBusinessLayer.AddEmployee(student);

            return RedirectToAction("Index");

        }

     
    }
}
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*****************

@model BusinessLayer.Student

@{
    ViewBag.Title = "Details";
}

<h2>Details</h2>

<fieldset>
    <legend>Student</legend>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.SId)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.SId)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.Name)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Name)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.Age)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Age)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.Gender)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Gender)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.Course)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Course)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.Departement)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Departement)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.Place)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Place)
    </div>
</fieldset>
<p>
    @Html.ActionLink("Edit", "Edit", new {  id=Model.SId }) |
    @Html.ActionLink("Back to List", "Index")
</p>
********************************************************


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend