using namespace in Layout.cshtml?

Topics: Writing modules, Writing themes
Dec 13, 2011 at 4:35 PM

I have a Widget I've built but want to hardcode part of it's view in my Layout. It uses some namespaces from the module. How do I add using statement in Layout? Or is this necessary? Will the proper namespaces be picked up without adding them to Layout?




Dec 13, 2011 at 4:36 PM


 @using Orchard.Mvc.Html
Dec 13, 2011 at 8:08 PM

Using is just syntactic sugar so that you don't have to fully-qualify everything every time. It does not mean you don't have to also reference the code that you're using. That is done at the level of project references.

In any case, I'm curious as to why why why you want to do that. Layout should remain clean, with only layout and zone definitions. Code in there should only be layout related, it should not be application logic.

Dec 13, 2011 at 8:41 PM

Well I have a partial view in a module that has a section:


@model Pryor.Data.Models.ISeminars
@using Orchard.Mvc.Html
@using Pryor.Data.Models
@using (Html.BeginFormAntiForgeryPost())
<div id="zipbottom">
    <p id="yourzip"> Your zip code</p>
    <div id="AlertMessage">@Model.SelectedZipCode</div>
    @Html.TextBoxFor(m => Model.SelectedZipCode)
    <button type="submit">Update</button>

This is in my partial view. It's a Widget.
 I want to Hardcode the textbox and submit button so that everytime some one drops the widget into the zone, the textbox and 
submit button doesn't get rendered every single time they add a widget. The textbox should appear once on the page but the functionality
it has tied to the widget should stay in play.

I don't know if that makes sense.


Dec 13, 2011 at 9:02 PM

It would be a lot cleaner if your widget newed up a shape and added it to one of the layout zones. It can also set a flag right on the layout to say that it's been done and other instances of the widget don't do it again.