ASP.NET MVC - Simple Breadcrumbs (SiteMap) - asp.net-mvc-2

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.

Related

Declare functions in ASP.NET WebPages

Is it possible to declare functions (as you would do in C# not javascript) or create classes in ASP.NET Web Pages?
How about in MVC, in the View files?
If not, is there anyway to do event handling in Web Pages? (Again, NOT javascript eventhandling)
You can create your own functions within .cshtml files. This article explains the functions keyword and how to use it: http://www.mikesdotnetting.com/Article/173/The-Difference-Between-#Helpers-and-#Functions-In-WebMatrix. If you include it in the .cshtml file that also makes use of the function, you cannot call it from other pages. If you wanted to do that, you can add a function to a .cshtml file and then put that in App_Code.
There are no events as such in ASP.NET Web Pages. You can check to see if a page has been posted back using the IsPost property.
If you want to make use of reusable utility methods in MVC, you are better off taking the more traditional approach of creating static classes and adding your methods there. App_Code is really for Web Site projects (ASP.NET Web Pages) as opposed to Web Application projects (whcih is what MVC apps are).

Where to place code shared between two pages in an ASP.NET Web Forms?

I have an ASP.NET Web Forms application.
In this application I have a Login.aspx page with code behind. Now I would like to create LoginLight.aspx lightweight version of Login.aspx page.
The light version should have less HTML content and should use the key functions of Login.aspx.vb code behind. These functions have a lot of code.
Therefore, in order not to have a lot of duplicate code, I would like to move the common functions to a common file. I was thinking about placing those functions in a class library in the App_Code folder but I read on the web that is not a good solution.
I also read that to have the same code behind for two different pages because it is not a good practice. How would I tackle this issue?
Create a base page that has all the functionality that you want shared.
Login.aspx and LoginLight.aspx will both inherit that base page.

Is it possible to use Mvc3 razor scripts aspx page view?

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.

MVC Convention over Configuration

I'm building a .NET MVC application. This is mobile web and i cannot use jQuery.
In my application every process is a 3 step action witch leads me to a 3 aspx per process.
My processes can be categorized so i'd like to code my controllers like: ProcessTypeAController, ProcessTypeBController.
My Views should be like: \ProcessTypeA\Process1\1.aspx, \Views\ProcessTypeA\Process1\2.aspx and \Views\ProcessTypeA\Process1\3.aspx.
By convention this not work because the Controllers dont have the same "location" than Views.
Please Help in this question!
Thank U ALL.
You could specify the location of a view:
return View("~/Views/ProcessTypeA/Process1/1.aspx");
As an alternative you could write a custom view engine in order to modify the default view location conventions. Scott Hanselman wrote an excellent blog post about how this could be achieved.

How to have includes / elemnts in Zend framework

I'm new to Zend Framework.
I have a menu of tabs that is used on various views but I need to highlight which section the user is in.
I have seen placeholders but they don't seem very flexible and don't really do the job since I can't access any variables to see what area the user is in.
Normally I would do this as an include, but not sure where to go with Zend.
Thank you for any help.
Zend_Navigation takes care of all your navigation problems:
Zend Framework: Documentation: Zend_Navigation - Zend Framework Manual