Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I Render @Section within @Using.BegingForm()?

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?

like image 216
Jerrold Avatar asked May 28 '26 17:05

Jerrold


2 Answers

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
like image 102
Mrchief Avatar answered May 30 '26 07:05

Mrchief


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) 
like image 23
Shyju Avatar answered May 30 '26 06:05

Shyju



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!