Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you implement a @using across all Views in Asp.Net MVC 3?

All I want to do is include this:

@using MyProject.WebUI.Properties

Across all my views without having to type it in each View, is there a way to do that in the ViewStart or Web.Config? Thank you.

like image 310
naspinski Avatar asked Nov 15 '11 20:11

naspinski


People also ask

How TreeView is implemented in MVC?

ASP.Net MVC Razor does not have any TreeView class and hence the TreeView will be implemented using the jQuery jsTree plugin. The TreeView will be populated from Database using Entity Framework in ASP.Net MVC Razor.

Can one action method have multiple views?

Yes, it's possible. Just make sure your views have same view model. From a technical stand point, views don't have to have the same view model implemented within the same action. There's just as long as the controller passes in the expected type.

Which component in ASP.NET MVC can be used to pass data between Controller to view assume you have to pass current date and time?

To pass data from the controller to view, either ViewData or ViewBag can be used. To pass data from one controller to another controller, TempData can be used.


1 Answers

Add your namespace to the views web.config under the namespaces element:

<system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="MyProject.WebUI.Properties" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

Note that you might have to close and reopen the view file that you want intellisense in for these changes to take affect.

like image 84
amurra Avatar answered Sep 18 '22 19:09

amurra