Reputation: 51
just trying to fathom out LINQ to SQL and datacontext class. I am learning MVC coding and have a database with some test data. I have created my datacontext and have been able to get this far in the controller.
ClientClassesDataContext context2 = new ClientClassesDataContext();
var result2 = context2.up_GetClient(4,1);
up_GetClientResult myObject = result2.SingleOrDefault();
return View(myObject);
This returns a list of clients, my part I'm stuck at is how to pass this to the view and put it in a grid style. Even passing the object to the view with only one row of data, I'm kinda stuck on how t even access items and display in, say, a text box.
Even just any pointers or links on best practice for LINQ to SQL etc would be a great help. There seems to be a lot of varying info out there.
The View is empty with the code below.
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Test</h2>
</asp:Content>
Any help or pointers would be appreciated.
Upvotes: 1
Views: 525
Reputation: 10683
Model:
public class MyModel
{
IEnumerable<client> _getClient { get; set; }
}
Controller:
ClientClassesDataContext context2 = new ClientClassesDataContext();
var result2 = context2.up_GetClient(4,1);
MyModel _mymdl=new MyModel();
_mymdl._getClient = result2.SingleOrDefault();
return View(_mymdl);
VIew:
@model ProjectName.web.MyModel
@{
ViewBag.Title = "";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div>
foreach (var item in Model._getClient)
{
//Add your login to create Table
}
</div>
Upvotes: 1