I'm just getting started with ASP.NET MVC and am going through the NerdDinner tutorial. As I'm going through I'm trying to apply what I see with how I will develop my site. I have experience with WinForms and much of what I'm wanting to do is display large amounts of data contained in a database.
I have used DataGridView along with DataSets and DataTable accessing SQLite databases. Going through the NerdDinner tut I see mainly access to SQL Server through Linq to SQL and generating HTML tables rather than using ASP.NET Web UI Components such as GridView.
I like most of the functions and look that the Web UI Components can bring, but I'm not sure if they are necessary. How do you all decide when displaying lots of data from databases what display components to use?
By experience with MVC and ASP .Net Control, your better not user control in a ASP Web form application.
The point is that they work with view state that is against the pattern of MVC.
In the case of your DataGridView what I would do is to loop through the list with a foreach and output a table row.
Phil Haack has a good post of using the jQuery Grid plugin with MVC to create a more "out of the box" grid solution like what you would be used to with the ASP.NET controls you mention.
MvcContrib has a lot of great things to aid with ASP.NET MVC development. In this case the Grid would help you a lot. I've used it in the past and found it to be pretty slick.
If you're using jQuery as well, this article talks about integrating it with the jQuery datable--makes paging and sorting essentially no-effort/painless.
Related
Im new to using angularjs with webforms.
i am using asp.net 4.0 webforms project. It have a usercontrol(uc.ascx) with a textbox and I dynamically multiple of the usercontrols on a page(Default.aspx)..on this aspx page i have a text box which should display the sum of the values in the textboxes of the dynamically added usercontrol..
can some one help me on how i can achieve this?
I researched all over the internet but could find a proper tutorial that works with usercontrols and angularjs
Well I think your are looking into the wrong direction angularJs isn't similar to knockoutJS probably both of them have double binding, but definitely they are very different.
Angular is a Single page application that's built mostly for CRUD's applications, the typical architecture is to use a restFul web service behind angular (which is going to be your front end) and they communicate using JSON as the communitacion format, been that said, I'd suggest to move on ASP.NET web API and angular
this video could be helpful for you to get the whole picture.
EDIT:
Unfortunately i don't have an specific example for your scenario but I've found a couple of articles that may help you on your journey.
A good example of how to use knockout.js and asp.net definetelly you can look at it and take that as a good source for learn it and apply it to your case.
This is another example using a usercontrol with knockoutjs
take a look to this gibhub repo with and example of the proposed architecture
I am thinking about using on of the technologies mentioned in the title but I can't decide which one would be the best for me. I jsut looked at asp.net to get an idea of each technology but I think I need a mix of MVC and WebForms, so that is why I am asking..
I want the MVC structure in the app itself and in the URLs
I want easily create a gridview with paging and sorting and easily map it to an SQL Database
I want to style everything easily via CSS
After I looked at asp.net I think MVC3 would be great for me but I need this in combination with WebForms, as I saw the DataGridView Control will be the best choice for my gridview.
Does someone give me some ideas what the best might be for me ?
After a long time using PHP and HTML/JS I hate it to doe every little step and using precreated Controls I only need to map to a database and customize via css would be a great enhancement to speed development things up!
Thanks!
In my opinion you should opt for MVC 3 approach (given most of your points mentioned) combined with jQuery DataTables. This gives you a best of both worlds - a great data visualiser and all the advantages of MVC 3.
DataTables
http://datatables.net/
DataTables ASP.NET MVC 3 Tutorial on CodeProject
http://www.codeproject.com/Articles/155422/jQuery-DataTables-and-ASP-NET-MVC-Integration-Part
Additionally if you didn't want to use the jQuery Data Tables you could look into MVC 3 Web grid which is the built in DataGridView equivalent for MVC:
http://msdn.microsoft.com/en-us/magazine/hh288075.aspx
You can use MVC, with aspx, Where you can also use the webforms features that you wished for.
I know there can be a flame war about this, people would suggest different suggestions.
Go for what you want.
All of what you need is possible easily in ASP.NET MVC.
I'm getting ready to be responsible for leading the development of a small ASP.net MVC application. This is my first time creating an MVC application, so I am excited!
I've carefully read over the documentation and I feel like I have the general idea of how MVC works. However, if I understand correctly, server controls (like GridView, for instance) are not part of MVC.
My question is: Why? At my development shop, I'm so used to using controls like GridView and the MS Chart Controls that I'm almost at a complete loss as to developing without them. It seems almost like starting over.
Why are the server controls unavailable? How does Microsoft expect me to work without them? What are the alternatives?
My question is: Why?
Because most of them depend on things like ViewState and the Postback models which are part of the classic WebForms model and no longer exist in ASP.NET MVC. Those server side controls rely on events that will perform postbacks to the server persisting their state in hidden fields (ViewState). In ASP.NET MVC you no longer work with events such as Button1_Click. In ASP.NET MVC you work with a Model, a Controller and View. The Controller is responsible for receiving user requests, querying the Model, translating the results into a view model and passing this view model to the View whose responsibility is to display it under some form.
In ASP.NET MVC there are HTML helpers that could be used to generate some reusable HTML fragments between views. You may take a look for example at the Telerik ASP.NET MVC suite of such helpers. They call them controls but they have nothing to do with classic WebForms server side controls. They are just HTML helpers.
Basically classic WebForms are a leaky abstraction of the web. What Microsoft did back in the time when they designed this framework was to bring existing Windows developer skills to the web which was getting more and more momentum. But since the web was still a new technology that most developers weren't yet familiar with, they created this abstraction to hide away the way that the www works. Those developers were accustomed to drag and dropping controls on their Windows Forms, double clicking on buttons that was generating some code for them in which they put their data access logic and so on. This model was transposed to web application development thanks to WebForms. The HTTP protocol was successfully hidden behind this abstraction called WebForms. For example you don't need to know HTML, nor Javascript, not even CSS in order to create a website using WebForms which is really great because the framework abstracts all those things for you. Unfortunately by doing so it prevents you from easily utilizing the full power of lower level web technologies which some people might need when developing web applications.
What ASP.NET MVC does is basically remove this leaky abstraction and bring the www to the developers the way it was intended to be by its creators. ASP.NET MVC is not mature enough compared to classic WebForms so you cannot expect to find the same range of available controls and widgets but things are slowly shifting.
I would recommend you start here with ASP.NET MVC: http://asp.net/mvc. Go ahead, watch the videos, play around with the samples and see if ASP.NET MVC is for you or not. And of course if you encounter some specific difficulty or question don't hesitate to come back here and ask it.
I'm so used to using controls like GridView and the MS Chart Controls that I'm almost at a complete loss as to developing without them. It seems almost like starting over.
In this case, starting over is good.
I've gone through a similar journey. If straight HTML scares you, try working with the System.Web.UI.HtmlControls namespace. This will allow you access to standard HTML controls, but you'll still have the comfort of turning them into server controls if you need to (either by specifying the runat="server" attribute, or by converting them into equivalent ASP.NET controls.
In addition to Darin's answer, there's another problem with ASP.NET: you're bound to Microsoft's view of the web. That GridView you love? It's generating bad HTML. The Paging controls it provides? Even worse. Even if you know very little about HTML compliance, nested tables should give you the chills. In a way, everyone who uses a GridView is lucky that legacy web supported by Microsoft (and to a lesser degree, Google and Mozilla) came from such a god awful starting point.
Finally, to summarize: my suggestion is that you try to rewrite your pages or develop new web applications (as best as you can) using HtmlControls only. You'll probably have to learn some JavaScript/jQuery, and might have to venture into the world of AJAX to make your controls operate the way you want them to.
Use this as a stepping stone into the world of MVC. You won't use the same technologies (and may drop a lot of JavaScript/jQuery), but it will help you change the way you think about web development in much smaller, and perhaps easier-to-absorb chunks.
Ultimately, however much you like your ASP.NET controls, you'll have a much greater degree of freedom, and you'll also be developing websites that make use of newer technologies, which will provide added value to your websites.
At the core of this is Model View Controller (MVC) which promotes decoupling. The idea is that you feed your View (web page) a Model with all the data that it needs to be rendered. Server controls are tightly coupled. There is no concept of state in MVC or 'should' be no concept anyways.
That's kind of the point of MVC. It takes away the high level of UI abstraction that server controls provided and leaves you with html and javascript. (It also adds some really cool model binding features)
I am new to MVC and have found using Partial Views to be similar in creating small, reusable UI elements that do not fit into the _Layout. For example, sliders, slideshows, navigation, featured sections although you can use #section for this I find partial views to be more beneficial. This concept enables me to create reusable libraries that I can switch out easily and use in other projects. To me this is similar to controls, although there is a debate both for and against this analogy.
I am currently evaluating ASP.NET MVC as a possible technology for a web project. As I am a beginner to ASP.NET MVC I need a bit of advice.
We currently have an ASP.NET system that renders grids from data that is retrieved from a database using OLE DB and data tables. The data is rendered on a web page using a grid view that uses the columns from the database. The system is built in a generic way and driven from the database so that we do not have to write a custom page to display and render each table in the database. We effectively have one ASP.NET page that is used to render and edit different tables in the database.
We are looking at rewriting the system using ASP.NET MVC. Is it possible to have generic models, controllers and viewers in ASP.NET MVC that use dictionaries or lists instead of having separate classes for each table in a database?
On the controller side I have seen the following article to convert a data table to an IEnumerable:
Convert DataTable to IEnumerable
However, I am not sure whether the same can be achieved on the model and viewer side.
Is the whole idea of generic models, controllers and views perhaps contrary to the idea of ASP.NET MVC?
Regards
Lucas
First, you don't need custom models for views or controllers if you know you will be using something generic.
Second, you can write editor/display templates that can work on generic data and you can use them in your views.
We are looking at rewriting the system using ASP.NET MVC. Is it possible to have generic models, controllers and viewers in ASP.NET MVC that use dictionaries or lists instead of having separate classes for each table in a database
Generic solutions are very often a excellent recipe for maintenance nightmare. They work well until you have to extend the application. In my experience you do not switch from the generic solution when you want something extra, but do a small workaround. Next time you'll add another small workaround. And after a year you do not want to touch that application again.
If that's not the case for you, congratulations! You can just use a DataTable as your model in the view.
I am trying to explain ASP.Net MVC 2 to my colleagues and the management. I have to develop a sample application in both ASP.Net and ASP.Net MVC 2 to show case the differences between the two.
What would be a good application that can bring out the differences between the two? I am planning to demonstrate performance and testability. Any other key points that I can demonstrate?
Any ideas is really appreciated.
If they're web developers that likes to keep up with all the latest stuff, show 'em your complete control over the generated source. Show them how they can create HTML5 compliant websites with no extra effort. No more (unless you want) viewstate or document wrapping form tags.
You could also show them the extensibility abilities with action filters and action results.
But, as you mentioned, the biggest win for everyone is testability.
Edit:
I can really recommend TardisBank as a great sample application. It uses MVC3 with Razor and RavenDB as the database. The code is well structured and clean.
Show them the page size, that should be helpful