Tuesday, June 4, 2013

Razor helpers Vs Partial views

Razor Helpers
A Razor Helper is defined as a function with a specific set of input parameters that outputs rendered markup. Razor Helpers are most suitable for helping customize small sections of markup with minimal logic, such as an anchor tag or image tag. Since they typically contain less application-specific logic, they can often be used not only across views within the same project but also shared between applications. Think of Razor
Helpers as templates or “macros” that make your code easier to read, write, and maintain.

Partial Views
Whereas Razor Helpers are best suited for small, generalized sections of markup, partial views are best for breaking up larger views into more manageable pieces. These pieces typically contain more application-specific markup and logic. Though partial views can be reused across views in a project, the application-specific logic present in most views generally precludes sharing across applications. Conversely, just because it is possible to reuse a partial view in more than one place doesn’t mean you have to. Partial views can be a very effective tool for simplifying a larger view or isolating a particularly complex section of a page. Do not shy away from creating a partial view because it will only be used in one place—not only is that OK,
it’s sometimes very helpful!

No comments:

Post a Comment