1

My razor web is big and padded with a lot of text that I would like to move into an external file. Right now it looks like this:

@if (Model.RowKey == "ABC") {
    <div class="mdl">
       50+ lines of textual information. Not code.
    </div>
}
@if (Model.RowKey == "DEF") {
    <div class="mdl">
       50+ lines of different textual information. Not code.
    </div>
}

Is there a way that I can store this text externally so I don't use too much space in my view? Also IF I store externally is there an overhead when the view is created? Will it have to recompile the view each time? This is very important as I want things to run quick.

Robert Dawson
  • 153
  • 1
  • 2
  • 10
  • Instead of trying to mask the amount of noise in your views, why don't you attempt to modularize them. Look at common "controls" such as login controls and person detail controls and create partial views from them. It promotes reuse as well as modularity and you can better test them. – Pieter Germishuys Jun 30 '11 at 05:19
  • I am trying to move out all the textual information. It's not code it's paragraphs of text. – Robert Dawson Jun 30 '11 at 05:21
  • Ahh, you could then create a view model that will be given this information from a database. i.e. Controller populates the ViewModel.SomeText, then view then gets passed this viewmodel and the view just uses the text @Model.SomeText given that the view is strongly typed. – Pieter Germishuys Jun 30 '11 at 05:29

2 Answers2

0

If Model in your code is the view's Model and not an enumerator variable (and if your content is purely static) you could try with a different view for each type of RowKey, and then in your controller do:

Return View("ABC");

Then in your Views folder you would have ABC.cshtml, DEF.cshtml, XYZ.cshtml, etc. All text will still be in the view (not really a problem there), but you will get rid of all those @if() blocks.

Daniel Liuzzi
  • 16,807
  • 8
  • 52
  • 57
0

You could use a Text.resx file to store the text and use Resources.Text.ABC to retrieve the text in the View

Wim
  • 1,967
  • 11
  • 19