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/
Related
Is it possible to do a KendoUI mobile project, using ASP.net mvc? Watching the introduction on Pluralsight, I'm sort of confused. As an example, KendoUI Mobile uses something like this to navigate:
<a href="#someView" data-role="button">Go to some view</button>
When rendering views through RenderBody in my main layout, will I have to specify this view as a mobile view, or does the application defined in my main layout pick up on this?
So, I guess my question is this; Has anyone got any experience on this combination and, if so, could you provide some resources as to where this combination is being used?
I figured this on out. Seems to be a few projects out there using this combination. One example is this project: KendoUI mobile task manager
That being said, I'll try to play around and tweak the framework to my needs.
The answer is Yes. I was searching for the same answers, and found this resource very helpful, using MVC4, with detailed explanations:
Single Page App using MVC and Kendo Mobile
When searching for references and tutorials, what is not immediately clear is that Kendo UI Mobile is a different setup from Kendo UI. As WhizKid points out it is a single page application, and all your data must go through AJAX.
If you have not used them before, you will probably need to learn Kendo's MVVM and datasources. You must decide what sort of interface you will use for data exchange (eg. WebApi, OData) and fix the routing.
The reason I am going this way is because Kendo comes with good looks, and MVC can help me with localization.
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.
Im building an ASP.NET MVC 3 app using Razor as template language.
Here is what I would like to do:
When all template content from cshtml-files for a certain request have been parsed in razor viewengine and ready to output to the visitor - then I would like to insert some extra information into the parsed html content.
So my question is:
Is there an event of any kind to hook on to inside the Razor viewengine or inside the MVC framework that allows me to do this kind of changes to the output?
Don't ask why I'd want to do something like this in a MVC application, it's a long and boring story.
Given the vagueness of your question, perhaps this article might help, or maybe you can specify in what way the article isn't helpful...
Dependency Injection in ASP.Net MVC Views
UPDATE:
How about an ActionFilter? I seem to recall that you can get the viewresult and tinker with it in an ActionFilter, although I have only ever done this for a json transformation. Here's another article: Use ASP.Net action filters to render
Here's a SO answer--this might be a duplicate question!
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.
I'm just browsing MVC examples so far, and I think I'm getting a handle on it. For my project - an embedded system on ARM9, no Windows/ASP at all - we are considering doing all the UI as MVC. Does MVC also require a strict Tree of all UI Views (one root?)
No, one controller may have different views for different actions.
You can split the controller into a front controller and several actions.
As reference see The MVC Pattern as implemented into Symfony framework.
If your views are parts of a full page you might also use the same view from different controllers. Ie header and footer.
A controller can have many views and partial views. If you take a look at some simple ASP .NET MVC tutorials: http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/intro-to-aspnet-mvc-4 you'll learn how this can be done easily.