1) IMO, Your views should never see anything as raw as a DataSet. You should use an ORM to translate your queries into objects and pass those to the view. Go download
Subsonic and give it a try.
2) Unless I'm mistaken, you're taking about a GridView control? If so I believe that requires a <form runat="server"> tag. I would STRONGLY recommend against doing that!
If you still want to do that, it's quite easy...
Simply write your data access layer to use sql.
public class MyDataAccessClass
{
public static DataSet GetProducts()
{
// use ado.net classes here to execute your sql and return your dataset
}
}
Then you can call this from your controller and pass the DataSet to the view.
In the code behind of the view, get the dataset from the ViewData and bind it to your grid.
However, as I said, This is not The MVC Way (tm).
---
As for your second problem, don't browse to /Views/Home/Index.aspx because that is bypassing MVC so the Html property will be null, you might even want to put a web.config file inside your Views directory to block all access. You should browse to
/Home/Index, or just /Home,or just /. (assuming you're using the default routes)
And as per MVC we are not supposed to use server side controls. But isn't it difficult? Without Major controls like GridView TextBox etc. Are we supposed to pass data as objects or list of objects only?isn't there any other way of doing it?and display it
as plain text? By doing the formatting ourselves. and for this we must be thorough in inline coding.
Could you please give me links that could help me know inline coding?
gayupk
Member
26 Points
60 Posts
sample code where sql is used instead of linq
May 05, 2008 08:54 AM|LINK
I do not know how to use Linq. Can anybody tell me how our Models in MVC can be frammed using Sql instead of linq as in Scott gu's 4th blog on Mvc.
I basically want an example showing how to pass a dataset to the view and display it in a grid.
I keep getting this error. Object reference not set to an instance of an object.
<ul>
Line 23: <li><a href="~/" runat="server">Home</a></li>
Line 24: <li><%= Html.ActionLink("About Us", "About", "Home") %></li>
Line 25: </ul>
tgmdbm
Contributor
4392 Points
883 Posts
ASPInsiders
MVP
Re: sample code where sql is used instead of linq
May 05, 2008 12:19 PM|LINK
1) IMO, Your views should never see anything as raw as a DataSet. You should use an ORM to translate your queries into objects and pass those to the view. Go download Subsonic and give it a try.
2) Unless I'm mistaken, you're taking about a GridView control? If so I believe that requires a <form runat="server"> tag. I would STRONGLY recommend against doing that!
If you still want to do that, it's quite easy...
Simply write your data access layer to use sql.
public class MyDataAccessClass { public static DataSet GetProducts() { // use ado.net classes here to execute your sql and return your dataset } }Then you can call this from your controller and pass the DataSet to the view.
In the code behind of the view, get the dataset from the ViewData and bind it to your grid.
However, as I said, This is not The MVC Way (tm).
---
As for your second problem, don't browse to /Views/Home/Index.aspx because that is bypassing MVC so the Html property will be null, you might even want to put a web.config file inside your Views directory to block all access. You should browse to /Home/Index, or just /Home, or just /. (assuming you're using the default routes)
gayupk
Member
26 Points
60 Posts
Re: sample code where sql is used instead of linq
May 05, 2008 12:43 PM|LINK
Thanks a lot.that helped.
And as per MVC we are not supposed to use server side controls. But isn't it difficult? Without Major controls like GridView TextBox etc. Are we supposed to pass data as objects or list of objects only?isn't there any other way of doing it?and display it as plain text? By doing the formatting ourselves. and for this we must be thorough in inline coding.
Could you please give me links that could help me know inline coding?
gayupk
Member
26 Points
60 Posts
Re: sample code where sql is used instead of linq
May 08, 2008 04:12 AM|LINK
I am not able to set the start up page to any of the above mentioned url tgmdbm. It says invalid format of url.
gayupk
Member
26 Points
60 Posts
Re: sample code where sql is used instead of linq
May 08, 2008 06:40 AM|LINK
Can anybody send me links from where i can download MVC architecture ppt.
Please. I need it urgently.
thanks in advance
gyan_flip
Member
129 Points
77 Posts
Re: sample code where sql is used instead of linq
May 08, 2008 07:01 AM|LINK
This URL may help you: http://www.civil.engineering.utoronto.ca/Assets/output/assets/mvc_1706650.pdf