I have an entity which has a list of some object and I want to let the user to add as much as he want from that object so that I can put them in the list.
how can I create that in razor view? should I use Ajax and if yes how?
You may take a look at the following blog post. It was written for ASP.NET MVC 2, but it is very good and those notions still apply in ASP.NET MVC 3. Adapting it to Razor would be trivial.
Related
I am very new to MVC and Presently I need to work on a Project in MVC4 with Razor engine.
So can any one tell me about
How to implement logic for SelectedIndex Change event of dropdwonlist in MVC4?
Thanks.
In MVC you can't do this. You'd need to use jQuery. OnSelectedIndexChange is a concept that is used in ASP.Net, and MVC3 is vastly different. If you want to implement logic when a user changes a DDL, you'd need a jQuery function to run when the DDL changes (onchange html attribute), which would then pass a request with AJAX to a controller on your page. Within this controller you'd be able to implement this logic.
I'd recommend getting familar with the concepts of MVC first. Practises in ASP.Net are rarely interchangeable with MVC.
I wanted to ask if anyone has tried using combination of Sencha's ExtJS 4 (using MVC approach) with ASP.NET MVC (using view models)?
I have existing ASP.NET MVC 3 app that uses view models and my question is how would this "fit" into Sencha's MVC approach...Would ASP.NET MVC "view model" become ExtJS "model" and then I would define yet another "view model" for ExtJS....Seems a lot of "translating"...
What would be the best approach?
And yes, I am aware of projects that integrate ASP.NET MVC with ExtJS using Ext.Direct, but my question is strictly relating to MVC paradigm on "both" sides (ASP.NET and Sencha ExtJS)
Thanks
Z...
Our approach currently is a what could be described as MVCCM or MVC-CM.
In ExtJs you have the view as panels and boxes etc, a store with a model makes a model and you need some logic to make these components work together which would be the controller.
This ExtJs frontend is situated in a MVC3 project and exposes controller methods that typically returns Json data which it gets from the model back end which is typically made up of entities.
There is no programmatic link between the entities on the server side and the models defined in the stores client side. One could generated the stores from entities, but we have not looked into this yet.
The view in the Microsoft MVC3 framework is just a page that returns some div tags which ExtJS can render stuff into.
While I've not done this with ExtJS, I really don't think there's any conflict. I'm assuming a lot here, I know, but if ExtJS works with JSON and you've got ASP.NET MVC actions that emit JSON, it's really more of a philosophic difference than a technical one.
One difference from a normal MVC app would be that your ASP.NET MVC app might not have any views, since the views would be handled entirely by ExtJS.
From the server side, ASP.NET MVC really doesn't care - it's getting a request that gets mapped to a controller and action, processing the request and returning some result. Whether that result is HTML, JSON, XML or whatever, ASP.NET doesn't care at all.
I don't want to make this into a "which is better... MVC or WebForms" type of question. Im sure that has been asked a bunch of times here already.
My Question: If I am building a MVC web project, why should I not use an ASP.NET datagrid control on one of my "Views" .aspx pages?
The control relies on Viewstate which isn't available in MVC. In addition, all the behavior is predicated on the WebForms event and postback model which you'd have to recreate in MVC to get them to work. You could search for alternate, MVC-friendly grids (perhaps jQuery-based). I know that Telerik has released a set of MVC controls under open source that might be helpful to you.
you can't use web forms controls in MVC because they depend on view state. Use the data grid of the Mvc Controls toolkit instead. It has paging, insert delete and update capabilities and it is completely templated (you can shap it as you like). Look at it here
The datagrid control depends on postback events which does not fit into the MVC way of thinking (the postback goes to the page code behind rather than the controller). You could use one without any postback features, i believe, but you may as well craft something directly.
Because the ASP.NET DataGrid / GridView has too much responsibility to fit into the MVC pattern. You'll have to add some code-behind to your view to databind the grid - code that belongs in the controller.
Anything that uses postback won't work with MVC, so the DataGrids paging and sorting won't be any good to you. So there really isn't any benefit to using it.
If you're looking for a flexible grid 'control' (MVC prefers the term HTML Helper), the MvcContrib grid is pretty good.
I know that ASP.NET MVC will allow me to swap in various View engines that other people have created, but I am wondering how can I create my own View engine?
More info:
We have our own webforms based CMS and the main selling point about MVC is that it gives us cleaner HTML (which our designers would love). However we have a desire to create our own domain-specific View implementation.
OK, I did some Google-fu and found these posts:
Adding support for skins in an ASP.NET MVC application
Partial Rendering & View Engines in ASP.NET MVC
I think I can work it out from what these guys say - I just hope that it still applies in the latest ASP.NET MVC drop!
EDIT: There is also a nice post about using VB.NET XML literals for a view engine.
It's too easy, here's what I did:
Create a class derived from VirtualPathProviderViewEngine (in fact, you can just copy WebFormsViewEngine and edit it slightly).
Create a class derived from IView. There's only one method - put your magic here.
In Global.asax.cs:
ViewEngines.Engines.Add( new MyEngine() );
Check out http://mvccontrib.org/ for a couple samples of different ViewEngines. There are 4 included (well, minus one that's obsolete but the code is still available)
I am in the middle of implementing an application using ASP.NET MVC and would love to cache the data passed to user controls or the output rendering on some user controls that I render using the Html.RenderPartial, that way I don't have to query the DB with every request I do to the controller for a new view.
That appears to be one of those 1 million dollar questions!
It seems that a lot of people are having that problem, but the solution is not trivial.
Check out an issue reported recently on the ASP.NET MVC Codeplex site...
I would maybe suggest using the sub controllers from the MVC Contrib and then caching the controller's method using the OutputCache stuff.