Home > DeveloperSection > Forums > Problem in View Code in MVC4
Gaurpriya Bishnoi
Gaurpriya Bishnoi

Total Post:7

Points:49
Posted on    July-16-2015 1:19 AM

 ASP.NET MVC LINQ  Mvc4 
Ratings:


 1 Reply(s)
 618  View(s)
Rate this:
hi i am face problem in view code

Controller
public ActionResult Testing()
        {
            //var res = (from empname in db.UserMasters
            //              select empname.EmployeeId).Distinct().ToList();
          //var res = db.UserMasters.Select(x=> new  UserMaster{EmployeeId=x.EmployeeId}).Distinct().ToList();
            var res = db.UserMasters.Select(x=>x.EmployeeId).Distinct();
            return View(res);
        }

View Code Here

@model IEnumerable<SampleApp.Models.UserMaster>
@{
    ViewBag.Title = "Testing";
}

@foreach (var item in Model)
{
    <li><a href="#">@item.EmployeeId</a></li>
}

screenshot




Pawan Shukla

Total Post:37

Points:267
Posted on    July-16-2015 7:39 AM

Hi Gauripriya

Change code in razor view file..
@model IEnumerable<SampleApp.Models.UserMaster>
Replace with
@model List<SampleApp.Models.UserMaster>

Don't want to miss updates? Please click the below button!

Follow MindStick