Git Product home page Git Product logo

Comments (1)

iloire avatar iloire commented on June 29, 2024

Hola Jess,

Va por muy buen camino tu sugerencia, la verdad es que de la manera que
está ahora no es muy elegante...
Pensaré en cambiarlo, gracias!!

iván

2012/1/11 jesusgarza <
[email protected]

Ivn,

Estoy comenzando a usar tu proyecto Invoicing-App y me est ayudando
mucho. Aprovecho para hacerte una sugerencia para Menu.cshtml: condicionar
la clase active usando un helper. Para eso se puede sacar cul es el
controlador y accin actual y pasarlo como parmetro:

Definir al inicio de Menu.cshtml una variable con el controlador-accin
actual:

@{
   string currentControllerAction =
ViewContext.Controller.ValueProvider.GetValue("controller").RawValue.ToString()
+ "/" +

 ViewContext.Controller.ValueProvider.GetValue("action").RawValue.ToString();
}

Y en el men, condicionar la clase usando el helper:

<li class="@iloire_Facturacion.Helpers.MenuHelper.GetCssClassForMenu(
currentControllerAction, "Invoice/Index")">
@Html.ActionLink("Invoices", "Index", "Invoice", new { proposal = false },
null)
</li>

El helper sera algo sencillo:

   public static class MenuHelper
   {
       public const string ACTIVE_MENU_CSS_CLASS = "active";
       public const string INACTIVE_MENU_CSS_CLASS = "inactive";

       public static string GetCssClassForMenu(string
currentControllerAction, string menuControllerAction)
       {
           if (currentControllerAction == menuControllerAction)
               return ACTIVE_MENU_CSS_CLASS;
           else
               return INACTIVE_MENU_CSS_CLASS;
       }
   }

Referencias:

http://blog.janjonas.net/2011-02-15/aspnet-mvc_3-get-controller-action-razor-view

http://www.arrangeactassert.com/asp-net-mvc-view-best-practices-keep-logic-out-of-your-views/


Reply to this email directly or view it on GitHub:
#3

Ivan Loire - www.iloire.com
Desarrollo y formacin .NET (MCT)
(+34) 654 249068 - [email protected]

from asp.net-mvc-example-invoicing-app.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.