Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC Razor RC 1: Can the @section be defined with a string constant?

Is there any way to use a string on a page using a master layout and calling a section?

So instead of this:

  @section SomeSection

I could do this?

  @section "SomeString" 

Or better

  @section SomeClass.SomeConstantString

Reason for this? So that I can use a constant string on the master page for the section name and use the same constant string on the partial page.

  @RenderSection(eClass.SomeConstantString, required:false)

I'm really hoping there is a way to do this otherwise it seems like an issue overall.

like image 893
Programmin Tool Avatar asked Nov 13 '10 17:11

Programmin Tool


People also ask

How do you define a variable in a Razor?

To declare a variable in the View using Razor syntax, we need to first create a code block by using @{ and } and then we can use the same syntax we use in the C#. In the above code, notice that we have created the Code block and then start writing C# syntax to declare and assign the variables.

Which of the following Razor syntax allows you to explicitly indicate the start of content?

Using @: to explicitly indicate the start of content.

How do I use Rendersection in partial view?

Rendering a Partial View You can render the partial view in the parent view using the HTML helper methods: @html. Partial() , @html. RenderPartial() , and @html. RenderAction() .

What is meaning of @: In .NET MVC?

The @: sequence indicates that the line of content that follows should be treated as a content block: ("razor at colon" in Google).


1 Answers

No, this is not possible. I don't see that as that big of a limitation because if the layout is rendering a required section and the names do not match you'll het an error at runtime.

like image 126
marcind Avatar answered Sep 28 '22 23:09

marcind