I have a requirement like my controller name will be coming from database like below
http://www.mysite.com/ParkName
I'm using ASP.Net mvc3
I'm not getting any perfect solution how to route that dynamic controller or do in better way.
Could any one please Guide me.
You can override DefaultControllerFactory to search controller type base on database name.
There is a simple example on Code Project
Related
So this is kind of a semantic question I suppose. But in my WebAPI project, I have a view that is supposed to allow a user to find resources (it doesnt matter what the resources are). So I created a controller called FindResourceController which is derived from Controller. I then create my view using razor and jQuery. And my controller has a method, called Index which returns this view.
All good so far. But I ALSO want a ApiController to handle jQuery requests from my FindResource view. By convention out of the box, API urls are routed like api/FindResource/, so I should name my api controller FindResourceController and derive it from ApiController. But I already have this class. So then I could name it FindResourceApiControler, but the url maps to api/FindResourceApi/ which seems redundant. This just seems kind of kludgy to me. So either I'm missing something, or this is just the way it is... so, when doing something like this what do you do in your web api project?
Edit: So far, this is all I have found
Link to Article
Is putting the types in a different namespace an option for you? You could have a Controllers namespace and an ApiControllers namespace and have a FindResourceController in each. It might cause some conflicts though so it's not a perfect solution, but it might work for you.
I am looking for a solution to dynamic configure the routing in ASP.NET MVC 3, based on the current language the user is using on the website.
now i have:
domain.com/de/controller/action/subaction/XX
domain.com/en/controller/action/subaction/XX
and i would like to have:
domain.com/de/bereich/aktion/unteraktion/XX
domain.com/en/controller/action/subaction/XX
the name for the controller/action & subaction should be configurable through the Database (the german names as well as the english ones)
As the default route configuration works well in ASP.NET MVC, i would prefer to use it, and e.g. just customize the class that handles the mapping between the URL and the controller (etc).
http://blog.maartenballiauw.be/post/2010/01/26/Translating-routes-%28ASPNET-MVC-and-Webforms%29.aspx this article will help you exactly with your problem but please think about it twice.
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.
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 am trying to migrate to zend framework. Should each webpage be a Controller or an action.
What is the advantage of having multiple actions. Can they talk to each other? and whats the best use of Action helpers and View helpers.
Please guide me on how to start on the framework.. thanks
You can use a new controller for each page or define multiple actions on the same controller to render your pages. I choose to use defferent action from the same controller to display variuos pages. Using multiple action on the same controller allows you to put some code in che constructor of the controller that is executed for each action. For example i have a controller for all the pulic pages of a website and a new controller for those pages that are reserved to registered users. In the constructor for the controller dedicated to registered user i do the check for authentication.
You should check that page about MVC applications, It's not precisely related to Zend. But you seems to be asking what a MVC Design Pattern is.
You got to create a controller for each of your site's pages. If any page interacts with db, you should also create model for that page. Also you should create view for each of your page.
If you have no idea about MVC, you can read this:
MVC
Those links are from Zend Framework manual.
Do not afraid and click - read the Introduction chapters - you will have all answers. ;-)
View helpers
Action helpers
Action Controllers
First get a sound understand of MVC Framework:
Understanding MVC Architecture from its Origin (part I)
http://learnnewprogramming.com/blog/understanding-mvc-architecture/