I've an ASPNET MVC4 project using WebApi, EF5 Code First and Repository and Unit of Work patterns.
I'd like to know if someone knows a scaffolder to scaffold the controllers and views, but instead of using something like this, I'd like the views to have a script associated with jquery requesting something from the webapi controllers, and not returning a View from the controllers.
And if possible scaffold unit testing as well.
What's the best jquery grid (open source and free) out there?
Thanks in advance! Guillermo.
Related
So the way I've always worked with MVC in .Net is to create ViewModels for each View.
Now, with using Knockout, would I create my ViewModels in javascript instead of a C# class? And then have my main Model(in this case, EF generated Models) as my only C# Model classes? Or would I still go about create a C# ViewModel class along with my Knockout ViewModel?
I'm trying to set this project up DRYly, but I'm not sure of best practices in this situation.
You can create viewmodels (VMs) for the C# server side and still have them intended for the ASP.NET MVC Views. Then create VMs for the client side javascript views too. But the way I;ve liked it best is to use the MVC Views as the basis for the page, and have the Models be the basis for the JavaScript models. The only VM would then be the JavaScript VM since most of the presentation is really done client side. In other words, do the more static plumbing in MVC, then do the dynamic interaction client side.
If you are building primarily using client side JS libraries like KO I would not start with a VM for the MVC side unless you have a strong reason for it.
If you have specific questions, I'd be happy to try to help.
Create view models as you always do.
Create a HTML helper which generates a KO view model from it.
You should base your Knockout viewmodel on the view data from the server in order to at least have it initialized with data from the server without having to make a separate request to get that data.
You can optionally use the mapping plugin to map the view data to your viewmodel.
We've an ASP.Net MVC2 web app (SQL 2008 in backend). We use Data Annotations at model level for all sprt of validations (hope its one of the best practices). So, our validations are performed on server side and errors (if any) are returned. Works fine.
Next, we've AJAX based postback jQuery plugin. In combination with MVC partial views, we've 'AJAXified' certain forms. I hope this is pretty much like a basic stuff with a little AJAX & jQuery.
Now, we want to bring the validation on client side as well (and still
persist the server side validation). We've found some simple &
basic way to have basic validations like required, format,
range, etc... using bassistance jQuery. But what about certain server
side validations, like duplication check, etc.. what are the best
practices?
Note that we've simplified our web app by not including the default Microsoft AJAX libraries. We prefer simplified jQuery plugins. Also Microsoft js files weight several KB. Though it might lesson the effort but it requires several files.(Data Annotations Validation + jQuery.Ajax Post)
For example, jquery forms plugin looks simpler then the default MicrosoftAjax.
jQuery plugins are abstract & self contained thats one reason we're away from the Microsoft scripts. Here're some options -
SOLUTION #1:
Using ASP.Net Data Annotations validations using pure jQuery, AJAX,
JSON & Partial views
SOLUTION #2:
ASP.NET MVC Client-Side Validation Summary with jQuery Validation Plugin
We need to keep things simple, clean and optimal. For example, this looks complex -
ASP.Net MVC: Can you use Data Annotations / Validation with an AJAX / jQuery call?
If possible we'd prefer to keep the validation in one place instead of having to replicate it in data annotations as well as in jQuery.
Thank you.
But what about certain server side validations, like duplication
check, etc.. what are the best practices?
In ASP.NET MVC 3 you could use the [Remote] data annotation.
In ASP.NET MVC 2 it doesn't exist but you could implement it using jQuery.validate remote rule. This assumes that you use the jQuery validate plugin of course instead of the built-in Microsoft client side validation framework.
Microsoft scripts are now obsolete. If you want to ease the migration towards ASP.NET MVC 3 and even 4 you should forget about those and use jQuery and jQuery validate which are the default client side frameworks now in ASP.NET MVC.
I have to create custom controls in ASP.NET MVC 3. Controls like customized buttons which I will put in DLL and reuse in any project.
Do you know a good way or maybe you can give me a good tutorial to do this.
Thanks.
You can't, WebControls are for Web Forms. In asp.net mvc anything view related(html, javascript, css) is decoupled from the controller. The best you can do is to have helpers which are simply extension methods. But something similar to the webcontrols is specific to web forms only.
This post and this should give you an idea
You would need to use Partial Views to re-use code.
http://rachelappel.com/razor/partial-views-in-asp-net-mvc-3-w-the-razor-view-engine/
The best thing I like about ASP.NET MVC, is that you can directly call a server method (called action), from the client. This is so convenient, and so straightforward, that I really like to implement such a model in ASP.NET WebForms too.
However, in ASP.NET WebForms, to call a server method from the client, you should either use Page Methods, or Web Services, both of which use SOAP as their communication protocol (though JSON can also be used).
There is also another substitution, which is using Generic Handlers. The problem with them however is that, a separate Generic Handler should be written for each server method. In other words, each Generic Handler works like a simple method.
Is there anyway else to imitate MVC model in ASP.NET WebForms?
Please note that I can't change to MVC platform right now, cause the project at our hand is a big project and we don't have required resources and time to change our platform. What we seek, is a simple MVC model implementation for our AJAX calls. A problem that we have with Web Services, is the known problem of SoapException, and we're not interested in creating custom SoapExctensions.
You can mix ASP.NET MVC and ASP.NET Webforms in the same project. You'll just need to add the correct MVC parts to your current Webforms project and have the best of both worlds.
http://www.aspnetmvcninja.com/general/mixing-asp-net-mvc-and-webforms has a good walkthrough of all the steps you'll need to take to get it working.
You can splice your asp.net webforms app with something like Nancy perhaps?
I've had great success with Nancy and Knockout after I abandoned the horrible Ajax Control Toolkit.
(Apologies if I have misunderstood your question - I read it twice)
I need to render an ASP.NET MVC view to a string so as to be able to send it via an email (it is an order confirmation email defined in an .ascx file ).
I've successfully been able to render an ASP.NET MVC View to string using one of the methods in this question.
However now I need to be able to do it via a WCF service (that will be accessed via silverlight) and so I don't have a ControllerContext. This WCF service is contained within the same project as my MVC project so has access to all my models etc.
I've looked at several questions on Stackoverflow about this issue, but they all seem to need a controller context. I thought there was something in mvccontrib but it doesn't seem to be there anymore.
The closest I've found is the accepted answer to the aforementioned question, but it unfortunately breaks with RenderPartial within the view you're rendering.
I'm hoping maybe some of the behind the scenes work for ASP.NET MVC 2 related to RenderAction may help make this possible now?
BuildStarted and I have put together a standalone Razor templating engine which you might find useful (Github). You'll need to adapt your .ascx content into a simple string template, but it should do the job.
If you've got NuGet, you can run Install-Package RazorEngine
You may checkout the following blog post. Also Postal is worth looking at.
You need to create a fake HttpContextBase with a fake HttpRequestBase that return meaningful values from their properties.