everyone. I've got ServiceStack project and I want to add mvc part(some controllers and views) to it.
I tried just installed MVC and add an area, but it doesn't work.
I tried create new MVC project in the solution, but they work separately.(but I have no ideas how to merge their routes)
Any suggestions?
To use ServiceStack with ASP.NET MVC you need to configure ServiceStack to be hosted on a custom route e.g. /api this way ServiceStack doesn't conflict with ASP.NET MVC Razor handling and you can have ServiceStack handle all Service Routes from /api.
Configure ASP.NET MVC with ServiceStack
Access ServiceStack from MVC
Otherwise you can just use ServiceStack's Razor Support, in which case it can't be used with ASP.NET MVC (as it conflicts and tries to hijack Razor views), so to use ServiceStack Razor start with an empty ASP.NET Project and add the NuGet package:
PM> Install-Package ServiceStack.Razor
and register the RazorFormat plugin, e.g:
Plugins.Add(new RazorFormat());
You can find info about ServiceStack.Razor on razor.servicestack.net
Related
How to add an ASP.NET MVC project to an existing ASP.NET Web forms application. How to call MVC project page from existing website.
You can refer this step-by-step guide on how to do that.
Your question is similar to
Is it possible to host an asp.net MVC in the same folder as asp.net web forms app?
We were in the exact same situation as you and it's not as bad as you might think. Thanks to Nuget it's a fairly easy process that you can follow and Dave Paquette describes how to do it in his blog post
And once you've got Mvc up and running all you need to do to go from one to the other is to redirect to Mvc from webforms:
Response.Redirect("~/Controller/Action/")
You can also use the Mvc routing system to generate routes from within webforms as well:
System.Web.Mvc.UrlHelper url = new System.Web.Mvc.UrlHelper(HttpContexxt.Current.Request.requestContext)
Response.Redirect(url.Action("Action", "Controller"))
All the action is client side in a SPA app. The Visual Studio Durandal and Hot Towel project templates both serve the SPA out of an ASP.NET MVC application.
What, if anything, does the ASP.NET MVC infrastructure bring to the party? As far I can see all it does is make it hard to serve a WCF Web Service (ajax enabled) out of the project web.
Yet both of the project templates are set up like this. What have I missed?
As a matter of fact, ASP.NET MVC in this template is not necessary. All it does is serve the initial Razor template for the SPA and provides you with the bundling and optimization support of all the client side javascript resources for the application so that when you deploy your application you don't end up with gazillions of HTTP requests from the client to fetch all the .js crap necessary for the application to work. Of course you could perfectly fine have used the bundling feature outside of ASP.NET MVC in a simple and plain ASP.NET web application.
What, if anything, does the ASP.NET MVC infrastructure bring to the party?
See the documentation:
Hot Towel builds on the familiar and powerful ASP.NET MVC structure.
App_Start
Content
Controllers
Models
Scripts
Views
As far I can see all it does is make it hard to serve a WCF Web Service (ajax enabled) out of the project
You can't just right-click your project and add a new WCF Service?
When I create a MVC4 project and choose basic mvc project
I find WebApi related code why this?
Because Microsoft hope that you will use Web API 8-)
http://www.asp.net/web-api
If you don't want to, you can ignore it or even comment it in Global.asax
// WebApiConfig.Register(GlobalConfiguration.Configuration);
What is the difference between WebApiConfig.cs and RouteConfig.cs in the App_Start folder of an MVC Web API project in Visual Studio 2012?
The following are the key differences:
RouteConfig.cs is exclusively for configuring ASP.NET routes.
WebApiConfig.cs is for any Web API related configuration, including Web-API-specific routes, Web API services, and other Web API settings.
As cmotley mentions, the ASP.NET web site includes a good listing of what types of configuration can be done in WebApiConfig.cs in this article.
There is no difference as they both accomplish the same thing - adding routes to your route collection. You don't need to use the WebApiConfig class; it's simply a convenient way to organize your code.
If you are familiar with ASP.NET MVC, Web API routing is very similar to MVC routing. The main difference is that Web API uses the HTTP method, not the URI path, to select the action. You can also use MVC-style routing in Web API. This article does not assume any knowledge of ASP.NET MVC.
From Routing in ASP.NET Web API
We have an existing ASP.Net Web Application. I would like to create an ASP.Net MVC Razor Application where the two applications will work together. A single Master Page would contain menu items that can call .aspx pages as well as Razor .cshtml pages.
I have seen an example using MvcContrib Portable areas utilizing Routing. This particular example has .aspx pages in both (the MVC was not Razor).
Is there an example out there that will show the two running side-by-side and the MVC is Razor? It would be best if I could download a visual Studio Solution so that I can run this.
I am not sure if the MvcContrib way is the latest and best way to achieve this.
I do not want to go Hybrid!
You don't need any other external librarry. You can always convert the existing ASP.NET web forms Project to be a Hybrid one which uses webforms and MVC. You need to add the required MVC assembly references and make some changes to the web.config and you are all set. Scott has a simple and awesome blog post about this where he explains how to do the conversion.
I scribbled a note about how to enable the MVC specific Context menu( Add Controller / Add View) in the hybrid project after conversion here