3

I'm trying to render a custom section within a form in VB.NET MVC3? the section is in the master layout, and is defaulted - but id like to create a custom one when in a particular view

when i try

@Using Html.BeginForm()
..my markup
   @Section footerMenu
      ..custom footer markup
   End Section
End Using

EDIT: The Section is delcared in my _Layout.vbhtml

<div id="footer">      
    @If (IsSectionDefined("footerMenu")) Then
        @RenderSection("footerMenu")    
    Else
    ...default markup    
    End If
</div>

I get this error:

Unexpected "Section" keyword after "@" character. Once inside code, you do not need to prefix constructs like "Section" with "@".

Of course removing the "@" causes another error:

Compiler Error Message: BC30451: 'Section' is not declared. It may be inaccessible due to its protection level.

Is this possible to do?

Jerrold
  • 1,534
  • 6
  • 25
  • 43
  • Are you attempting to have multiple forms on your page? – Joel Etherton Jun 20 '12 at 17:08
  • well my problem is that i have a menu, that exists in the master Layout...which is fine, and is accessible by everyone - the problem is when a user navigates to a form, id like to keep the (possibly partially filled in) info of that form when they navigate out - so when they go "back" i can refill the form back since the menu is in layout, im having trouble passing the model back and forth - so i figured i can have a "default" menu, but in the form views render the menu within the form so that i can pass the model shrug – Jerrold Jun 20 '12 at 17:59

2 Answers2

3

You define section elsewhere and render them in your form. What you're doing here is defining section within the form which is causing the error.

And you need to create a custom one (to keep things simple basically)

So what you need is something like this:

@Using Html.BeginForm()
..my markup
   @RenderSection("footerMenuCustom") 
End Using

Elsewhere (can be a partial view)

@Section footerMenuCustom 
... Markup...
End Section
Mrchief
  • 75,126
  • 20
  • 142
  • 189
  • My apologies - im declaring (i guess?) the section in the _Layout - then in the view trying to define my custom one. I'll edit the post to reflec that. – Jerrold Jun 20 '12 at 17:05
  • You _render_ sections in your layout that are defined elsewhere. You're thinking the other way round. You cannot override sections per se but have the section load different partial views based on some condition. That way, you can set the special condition in your view which will cause the section to load the other partial view. Makes sense? See this for reference: http://stackoverflow.com/questions/7097162/conditional-asp-net-mvc-razor-sections – Mrchief Jun 20 '12 at 17:08
1

In your Layout page, Specify the the isRequired value is false . So that it will not throw an error even if you dont provide the content from some of the detail page

@RenderSection("footerMenu",false) 
Shyju
  • 214,206
  • 104
  • 411
  • 497