What is the best solution for displaying data in ASP.NET MVC? - asp.net

I am new to ASP.NET MVC and I want to know your opinion about what is the best way to display some data from database using a <table>... an ASP.NET control or a jqGrid?
In which situation must each of them be used?
I appreciate any tips. Thanks.

If I understand correctly, the MVC model doesn't support the server-side event handling of standard asp.net controls, so I'd say that the jquery grid is definitely the best option.

Asp.net controls cannot be used in asp.net mvc.
The best way is to create a ViewModel classes and declare View as strongly typed.
I could continue but unfortunately don't know what exactly do you need.

Do you mean ASP.NET Controls or ASP.NET MVC Controls?
ASP.NET Server Controls should not be used in this framework... or rather, you should not use anything that relies on postbacks and/or viewstate. There are tricks to get some to work, but YMMV.
If the control is an ASP.NET MVC Control, that's a different story, and it will work ok.
JQuery controls also work since they are javascript controls.

use the MvcContrib grid. it is working fine

Related

ASPX VS CSHTML to do grid processing

I need to write a web page which I need to interact with Grid entry/edit.
I choose ASP.Net MVC and LINQ TO Entity Framework.
What my problem is I have two option to choose at View Layer.
ASPX
Razor CSHTML
Could someone please give me suggestion which one is more suitable to interact Grid Entry Edit process? And Why?
If there are any references , please let me see them also.
[UPDATED]
JQUERY Grid
Telerik Grid for ASP.NET MVC
Razor Web Grid
After I searching through at Google, I get more than one Grid Controls.
I still wondering which one I need to use.
When I was writing with net 2.0 framework, I use template control from GridView Control in traditional way to put Combo or some other controls to attatch with GridView.It is really useful.
So What i thinking is, at asp net MVC 3 version, should i also use these traditional technique as well.
Could anyone please give me suggestion?
Razor is simply more concise. Both Razor and WebForms will offer the same basic functionality, but Razor results in Views that are much less cluttered and therefore more easily understood.
View engines have nothing to do with this. They both provide the same functionality, which you use is up to you and your preference.
There are many kinds of grids available for MVC, but MVC itself does not come with a grid. You either have to build the grid yourself, or use a third party component, most of which are jQuery based. Again, it's up to you what to use, as it's your preference.
All you can do is choose something and go with it. If it doesn't work for you, choose something else. MVC is a technology that requires you to know much more about how the framework works. If you want point and click and drag and drop, you should go back to Web Forms.
.chtm provides "Mapping of Data(or Business) objects that Your UI needs to Render(the html)" in a isolated way, so you can control the Test Cases for your UI as well as your Business Object Unit testing, which is Hard using ASPX since you have to create HTTPContext and (SSL and all crap) just to TEST your Business Logic..in short .cshmt is more NEATLY TESTABLE than aspx.

Best way to handle common HTML Controls on ASP.NET

I was wondering, whats the best way to handle common HTML controls in ASP.NET? I mean, ASP.NET server controls generate too much crap inside the code so I rather use common controls.
But how about databind and how to manage those common objects correctly (such as combobox, textbox and so on)?
Don't forget that you can always set runat="server" on any control - that includes standard html form controls such as <input> and <select>, and also other elements like <div>. Anything, really.
This means that you can regain control of the html output in your WebForms pages quite effortlessly - as long as you don't need viewstate or any other more advanced databinding/state managing that ASP.NET normally handles for you.
That said, learning to use the ASP.NET MVC Framework is not a bad idea, since it helps you regain control of much more than just the html output. Generally, creating a page in ASP.NET MVC takes a little more work, since there are no drag-n-drop controls like gridview, textbox or even repeater. Instead, you use html helper methods and regular foreach loops, which means you have to type a lot more code. However, the MVC framework is designed so that you won't have to repeat much code anyway.
If you're concerned about the html markup generated by the WebForms ASP.NET engine, i suggest you take a look at ASP.NET MVC. It's purpose is specifically to give you the control you need over the generated html.
If you don't want to start learning ASP.NET MVC, ASP.NET 4.0 WebForms gives you more flexibility in the generated HTML (such as enabling the ViewState for a specific control only, setting the html id's etc.).
As for the databinding, again if you study MVC in depth and start thinking in terms of action -> result you can gain a lot more control and flexibility.
Later edit: I forgot to mention Razor, the new ViewEngine under development at microsoft. It's currently in beta and only inside WebMatrix, a very stripped down 'getting-started type' development platform for ASP.NET. MVC combined with the very clean code you can write using Razor will be in my opinion an important trend-setter in the web development world.
There's a reason ASP.Net controls generate all that "crap". It's so you can databind and manage those objects correctly. Using standard html controls is useful when you don't need direct databinding or if you have no need to manipulate the control through server-side code.
The best way to handle common HTML controls in ASP.Net is not to handle them directly. By using them to handle data and functionality, you're basically neutering .Net. You might as well go back to classic ASP.

Asp.net gridview MVC

Can i create a gridview control in Asp.net MVC,and set its DataSource propertie and DataBind method,mormally as in web forms?
No - ASP.NET MVC has no ViewState and therefore no native WebForms controls will work.
There are a number of hybrid approaches for people who wish to use controls in MVC but if you wish to work in that way it would be better to use WebForms.
Technically it is possible - wrap the grid inside a <form runat="server"> tag and you are back in the WebForms business - ViewState, postback etc. However I would too not recommend this approach. You better use a mixed WebForms-MVC approach. You can also check the available grid solutions for MVC.

server side control in MVC

can we use server side controls in MVC, if no then why server side control list appears.
If you use the webforms viewengine (default) you can use the controls that doesn't use viewstate in asp.net mvc as well. And if you add a form with the attribute runat="server" you can use the controls that use viewstate as well. But I'd tell you not to use any of them even if you can. They don't really add any benefit for you anyway as you do not use your code-behind classes. You can't use them in the same way in your controller action.
No, not really, as they all rely on ViewState and a lot of the web forms plumbing. As to why they appear, I'd guess it's because you're on VS2008 and MS hadn't got a good way of telling one aspx page from another.

Dealing with ASP.Net Custom Controls in MVC

I have looked around on the Internet trying to answer this question. It seems to be kind of complicated though! Seems to come up with all sorts of different topics such as the HtmlHelper and other stuff.
Basically. How can you use custom controls with MVC? In a way that avoids doing anything that is frowned upon.
Also, Is it true that with MVC you have to put some simple logic IN THE PAGE? Isn't that what we should be getting away from?
Update: So, Seems you cannot use controls which depend on anything which MVC does away with, such as the postback events and viewstate. Can you make your own then? A control which does only rendering of course.
Can you use ASP.NET controls? Maybe. If the control does not use ViewState or postback events, it will probably work. For example, the LoginView control works just fine. Telerik supports ASP.NET MVC with some of their controls. On the other hand, if the control needs either ViewState or postbacks, then it just isn't going to work. Controls with data binding aren't ideal, since you typically have to use code behind him up. But they will work, if you add code behind.
On the other hand, controls with no knowledge of ASP.NET (such as the jQuery UI controls) work very well.
No, you don't have to put your logic in the page. You just don't put it on a code behind page, either. Instead, use helper methods.
With respect to the second question, the page is exactly where view logic should go. Any other logic should be in your controllers or models.
I'm not sure what you mean by custom controls. You can have ViewUserControls that are rendered via partials to reuse view code. If you are talking about 3rd part controls built for webforms, it's likely they won't work -- at least for awhile. If you absolutely must have them, though, there are ways to mix MVC with traditional webforms in the same site.

Resources