Is it possible to use Mvc3 razor scripts inside mvc 2 aspx page view and mvc 2 ascx control view?
I'm not sure what you are asking. What do you mean by "razor scripts"? Do you mean a razor partial? In that case, then yes. An aspx view can call a razor partial just fine (and vice versa).
If you mean embed a chunk of razor inside of an aspx/ascx, then no.
Razor is intended for MVC 3, but people have successfully gotten it working in MVC 2. Such as this question: How to Download Razor View Engine
In short No. You can use Razor and the WebForms view engines alongside each other, but you cannot mix them in the same view.
Besides, as far as I know, you can't use Razor with ASP.NET MVC 2 either although I'm not 100% sure on that last one.
Related
I have developed a ASP.NET MVC 2 application and I want to put a simple breadcrumbs (sitemap) in each page like this:
Home > Movies > Details
It is equal the URL: http://localhost/home/movies/details
How can I achieve it? I would like to put it in my master page.
Thanks!
I would recommend using MVCSiteMapProvider. It's available as a NuGet package.
It can be used to generate breadcrumbs (which you are probably asking about) and also site maps.
MvcSiteMapProvider is, as the name
implies, an ASP.NET MVC
SiteMapProvider implementation for the
ASP.NET MVC framework. Targeted at
ASP.NET MVC 2, it provides sitemap XML
functionality and interoperability
with the classic ASP.NET sitemap
controls, like the SiteMapPath control
for rendering breadcrumbs and the Menu
control.
Based on areas, controller and action
method names rather than hardcoded URL
references, sitemap nodes are
completely dynamic based on the
routing engine used in an application.
The dynamic character of ASP.NET MVC
is followed in the MvcSiteMapProvider:
there are numerous extensibility
points that allow you to extend the
basic functionality offered.
If it is always equal to the URL, the absolute simplest thing would be to make use of that by using something like this:
var menuitems = Request.Url.AbsolutePath.Split("/".ToCharArray(),
StringSplitOptions.RemoveEmptyEntries);
menuitems would now contain the menu items you need to perform a simple foreach loop and build your menu.
We have to migrate our asp.net mvc views, that use webforms view engine, into razor view engine.
The situation is that we have a group of web designers that uses dreamweaver to change the html of these files.
Do you know if there is something in dreamweaver to view correctly the razor code (i mean, hightlighted to easily read for them)?
Support for ASP.NET was dropped in Dreamweaver CS4 (current version is CS5), so any support would come only through a third-party plugin.
I followed Peters steps for adding cshtml to the list of editable files:
http://blog.metameister.com/blog/2011/04/08/open-new-file-types-and-add-syntax-highlighting-in-dreamweaver-cs5-on-windows-7/
Since Dreamweaver does not recognize Razor elements, this allows to edit the csHTML inside Dreamweaver, while in the design view you see the Razor parts is if they were text.
If your designers expect a design view, they might not be happy, if they are coder-designer how tweak raw (cs)html, then that might help them.
For me that is helpful, although I like the Visual Studio text editor a lot, writing text inside the page is sometimes easier with DW, for instance making some text goes by ctrl-b inside DW while I could not figure out a way to do this in VS by shortcut.
Razor is still in beta so I would be surprised if there are any plugins available yet.
Is there any way to alter the behavior of Url.Content rendering mechanism so that my static content in the page is loaded from an external server?
To explain further, suppose you have an ASP.NET MVC 2 website, http://www.example.com and at some point, your want your static content to be loaded from static.example.com . But you have coded your application with syntax like Url.Content("~/Content/images/a.gif"). From that point, is there some configuration change within the ASP.NET MVC to render these URL's as "http://static.example.com/Content/images/a.gif"?
Thanks in advance.
Unforunately there is no such configuration setting. Your best approach would be to write your own helper extension method hanging off of UrlHelper that you control.
Can i use mvc2 controls with new Razor engine?
If you mean all the extension methods (ie. Html.ActionLink etc.), yes of course, you'll use #Html.ActionLink() in Razor.
If you mean those Webforms like controls: <mvc:XXX.../> or <asp:XXX .../>: no. These are being rendered by the Webforms ViewEngine and Razor will just output them as HTML.
I have the MVC Telerik grid with one column as a hyper link. Whenever the user clicks on this link, I am loading a partial view using Ajax.
Within this partial view I have a Telerik MVC tabstrip control. The problem which I am currently facing is that I am not able to switch between the tabs of this tabstrip when it is rendered. Probably it is not able to reference its JavaScript files as it is loaded via Ajax.
I have already referred to the Telerik article of registering JavaScript files using the script registar:
<%= Html.Telerik().ScriptRegistrar()
.DefaultGroup(group => group
.Add("telerik.common.js")
.Add("telerik.component.js")
%>
However, the difference in this example is that here the tabstrip control is not loaded using Ajax. Only the content is loaded using Ajax whereas in my case I am loading the tabstrip control using Ajax.
How can I fix this problem?
I resolved it! If you face such an issue, refer to Telerik Extensions for ASP.NET MVC Manual.