asp.net mvc - Proper Razor syntax to use cms field as url for rss feed -


i'm brand new writing in razor , having trouble figuring out proper syntax. have written code embed , display rss feed content in .html page:

@using system.xml.xpath; @using system.xml;  @{     //fetch rss xml     xmltextreader udbrudrss = new xmltextreader("http://www.website.com/feed.rss");      //create new xml document     xmldocument doc = new xmldocument();      //load in our remote xml our xml document     doc.load(udbrudrss);      //select our nodes want xpath     xmlnodelist rssitems = doc.selectnodes("//item");  } <ul>     @{         //for each item node can ouput want         foreach (xmlnode node in rssitems)         {             <li>                 <div class="date">@node["pubdate"].innertext</div>                 <div class="message">@node["title"].innertext</div>             </li>         }     } </ul> 

this takes content feed.rss , embeds each post list item. perfect. now, make bit more scalable , dynamic, i'd control feed url through field inside cms. set field's data variable this:

var rssfeed = model.element("rssfeed"); 

and successfull in printing data on page this

@{html.renderpartial("editable/_rawdata", rssfeed);} 

so know data passing database page. can't figure out how combine these 2 users can control feed without touching template. this:

xmltextreader udbrudrss = new xmltextreader("@rssfeed"); 

any advice appreciated!

anything within @{} interpreted c# code. long xmltextreader line @{} section use variable name directly without quotes , without @. @ used signal when code starts. long it's withing @{} code block , have variable name rssfeed:

xmltextreader udbrudrss = new xmltextreader(rssfeed); 

you rewrite foreach loop this:

@foreach (xmlnode node in rssitems) {     <li>         <div class="date">@node["pubdate"].innertext</div>         <div class="message">@node["title"].innertext</div>     </li> } 

which preferred way it. way you're mixing code , html , using @ reference c# variables.

here's quick reference razor syntax:

http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx/


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -