<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5347040615161932801</id><updated>2024-10-17T06:52:30.839-07:00</updated><title type='text'>MVC 2 Tips</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://mvc2tips.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5347040615161932801/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://mvc2tips.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>jivangoyal</name><uri>http://www.blogger.com/profile/12853371042810428434</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5347040615161932801.post-3788970730795578945</id><published>2011-01-09T20:30:00.000-08:00</published><updated>2011-01-09T20:43:55.347-08:00</updated><title type='text'>Razor Syntax Sheet</title><content type='html'>&lt;table border=&quot;1&quot; cellpadding=&quot;2&quot; cellspacing=&quot;0&quot; style=&quot;width: 576px;&quot;&gt;&lt;col width=&quot;173&quot;&gt;&lt;/col&gt;  &lt;col width=&quot;170&quot;&gt;&lt;/col&gt;  &lt;col width=&quot;221&quot;&gt;&lt;/col&gt;  &lt;tbody&gt;
&lt;tr valign=&quot;TOP&quot;&gt;   &lt;th width=&quot;173&quot;&gt;Syntax/Sample&lt;/th&gt;   &lt;th width=&quot;170&quot;&gt;Web Forms&lt;/th&gt;   &lt;th width=&quot;221&quot;&gt;Razor&lt;/th&gt;  &lt;/tr&gt;
&lt;tr valign=&quot;TOP&quot;&gt;   &lt;td width=&quot;173&quot;&gt;Code Block&lt;/td&gt;   &lt;td width=&quot;170&quot;&gt;&lt;pre&gt;&amp;lt;%
  int x = 123; 
  string y = &quot;because.&quot;; 
%&amp;gt;&lt;/pre&gt;&lt;/td&gt;   &lt;td width=&quot;221&quot;&gt;&lt;pre&gt;@{ 
  int x = 123; 
  string y = &quot;because.&quot;;
}&lt;/pre&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr valign=&quot;TOP&quot;&gt;   &lt;td width=&quot;173&quot;&gt;Expression (Html Encoded)&lt;/td&gt;   &lt;td width=&quot;170&quot;&gt;&lt;pre&gt;&amp;lt;%: model.Message %&amp;gt;&lt;/pre&gt;&lt;/td&gt;   &lt;td width=&quot;221&quot;&gt;&lt;pre&gt;@model.Message&lt;/pre&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr valign=&quot;TOP&quot;&gt;   &lt;td width=&quot;173&quot;&gt;Expression (Unencoded)&lt;/td&gt;   &lt;td width=&quot;170&quot;&gt;&lt;pre&gt;&amp;lt;%= model.Message %&amp;gt;&lt;/pre&gt;&lt;/td&gt;   &lt;td width=&quot;221&quot;&gt;&lt;pre&gt;@Html.Raw(model.Message)&lt;/pre&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr valign=&quot;TOP&quot;&gt;   &lt;td width=&quot;173&quot;&gt;Combining Text and markup&lt;/td&gt;   &lt;td width=&quot;170&quot;&gt;&lt;pre&gt;&amp;lt;% foreach(var item in items) { %&amp;gt;
  &amp;lt;%: item.Prop %&amp;gt;;
&amp;lt;% } %&amp;gt;;&lt;/pre&gt;&lt;/td&gt;   &lt;td width=&quot;221&quot;&gt;&lt;pre&gt;@foreach(var item in items) {
  @item.Prop 
}&lt;/pre&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr valign=&quot;TOP&quot;&gt;   &lt;td width=&quot;173&quot;&gt;Mixing code and Plain text&lt;/td&gt;   &lt;td width=&quot;170&quot;&gt;&lt;pre&gt;&amp;lt;% if (foo) { %&amp;gt; 
  Plain Text 
&amp;lt;% } %&amp;gt;&lt;/pre&gt;&lt;/td&gt;   &lt;td width=&quot;221&quot;&gt;&lt;pre&gt;@if (foo) {
  &lt;text&gt;Plain Text&lt;/text&gt; 
}&lt;/pre&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr valign=&quot;TOP&quot;&gt;   &lt;td width=&quot;173&quot;&gt;Mixing code and plain text (alternate)&lt;/td&gt;   &lt;td width=&quot;170&quot;&gt;Same as above&lt;/td&gt;   &lt;td width=&quot;221&quot;&gt;&lt;pre&gt;@if (foo) {
  @:Plain Text is @bar
}&lt;/pre&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr valign=&quot;TOP&quot;&gt;   &lt;td width=&quot;173&quot;&gt;Email Addresses&lt;/td&gt;   &lt;td width=&quot;170&quot;&gt;Razor recognizes basic email format and is smart enough not to    treat the @ as a code delimiter&lt;/td&gt;   &lt;td width=&quot;221&quot;&gt;&lt;pre&gt;Hi philha@example.com&lt;/pre&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr valign=&quot;TOP&quot;&gt;   &lt;td width=&quot;173&quot;&gt;Explicit Expression&lt;/td&gt;   &lt;td width=&quot;170&quot;&gt;In this case, we need to be explicit about the expression by    using parentheses.&lt;/td&gt;   &lt;td width=&quot;221&quot;&gt;&lt;pre&gt;ISBN@(isbnNumber)&lt;/pre&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr valign=&quot;TOP&quot;&gt;   &lt;td width=&quot;173&quot;&gt;Escaping the @ sign&lt;/td&gt;   &lt;td width=&quot;170&quot;&gt;@@ renders a single @ in the response.&lt;/td&gt;   &lt;td width=&quot;221&quot;&gt;&lt;pre&gt;In Razor, you use the 
@@foo to display the value 
of foo&lt;/pre&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr valign=&quot;TOP&quot;&gt;   &lt;td width=&quot;173&quot;&gt;Server side Comment&lt;/td&gt;   &lt;td width=&quot;170&quot;&gt;&lt;pre&gt;&amp;lt;%--
This is a server side 
multiline comment
--%&amp;gt;&lt;/pre&gt;&lt;/td&gt;   &lt;td width=&quot;221&quot;&gt;&lt;pre&gt;@*
This is a server side 
multiline comment 
*@&lt;/pre&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;tr valign=&quot;TOP&quot;&gt;   &lt;td width=&quot;173&quot;&gt;Mixing expressions and text&lt;/td&gt;   &lt;td width=&quot;170&quot;&gt;&lt;pre&gt;Hello &amp;lt;%: title %&amp;gt;. &amp;lt;%: name %&amp;gt;.&lt;/pre&gt;&lt;/td&gt;   &lt;td width=&quot;221&quot;&gt;&lt;pre&gt;Hello @title. @name.&lt;/pre&gt;&lt;/td&gt;  &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;b&gt; referenced from: &lt;a href=&quot;http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed%3A+haacked+%28you%27ve+been+HAACKED%29&quot;&gt;haacked.com&lt;/a&gt;&lt;/b&gt;</content><link rel='replies' type='application/atom+xml' href='http://mvc2tips.blogspot.com/feeds/3788970730795578945/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mvc2tips.blogspot.com/2011/01/razor-syntax-sheet.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5347040615161932801/posts/default/3788970730795578945'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5347040615161932801/posts/default/3788970730795578945'/><link rel='alternate' type='text/html' href='http://mvc2tips.blogspot.com/2011/01/razor-syntax-sheet.html' title='Razor Syntax Sheet'/><author><name>jivangoyal</name><uri>http://www.blogger.com/profile/12853371042810428434</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5347040615161932801.post-8170093400088560869</id><published>2010-03-22T03:15:00.000-07:00</published><updated>2010-03-22T04:15:22.427-07:00</updated><title type='text'>Passing data while redirecting</title><content type='html'>In a controller action, while its required to redirect to some other action within same controller or action in other controller, it may require model/data to be passed too. The two simplest way to perform the same is&lt;br /&gt;1. Me.TempData(some string in quotes) = your class object/Model&lt;br /&gt;and this can be read at the target action code by using yourobject=Me.TempData(used string in quotes)&lt;br /&gt;&lt;br /&gt;   &quot;Where are data stored? This can be configured via &lt;em&gt;Controller.TempDataProvider&lt;/em&gt;  property which has type &lt;em&gt;ITempDataProvider&lt;/em&gt;. There are two main  implementations of this interface – &lt;em&gt;SessionTempDataProvider&lt;/em&gt;  (standard) and &lt;em&gt;CookieTempDataProvider&lt;/em&gt; (it’s suitable if we  don’t want to enable sessions).&lt;br /&gt;If we want to use some other temp-data-provider than &lt;em&gt;SessionTempDataProvider&lt;/em&gt;  then overrided &lt;em&gt;Initialize&lt;/em&gt; method of &lt;em&gt;Controller&lt;/em&gt; is  very good place where we should assign instance of favorited  temp-data-provider into &lt;em&gt;TempDataProvider&lt;/em&gt; property.&quot; [&lt;a href=&quot;http://www.augi.cz/programovani/aspnet-mvc-passing-data-when-redirecting/&quot;&gt;From&lt;/a&gt;]&lt;br /&gt;&lt;br /&gt;2. Using QueryString, like to redirect to action of other controller&lt;br /&gt;Return RedirectToAction(&quot;action name&quot;, &quot;controller name&quot;, your string to be passed)&lt;br /&gt;&lt;br /&gt;and at the target action we can use this by using&lt;br /&gt;&lt;pre id=&quot;codeVB0&quot; style=&quot;display: inline;&quot;&gt;Request.&lt;b&gt;QueryString&lt;/b&gt; ( your object name )&lt;br /&gt;&lt;br /&gt;Useful links:&lt;br /&gt;[&lt;a href=&quot;http://stackoverflow.com/questions/349742/how-do-you-test-your-request-querystring-variables&quot;&gt;How do you test your Request.QueryString[] variables&lt;/a&gt;]&lt;br /&gt;[&lt;a href=&quot;http://authors.aspalliance.com/aspxtreme/sys/web/httprequestclassquerystring.aspx&quot;&gt;refer&lt;/a&gt;1 &lt;a href=&quot;http://www.augi.cz/programovani/aspnet-mvc-passing-data-when-redirecting/&quot;&gt;refer2&lt;/a&gt;]&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://mvc2tips.blogspot.com/feeds/8170093400088560869/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mvc2tips.blogspot.com/2010/03/passing-data-while-redirecting.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5347040615161932801/posts/default/8170093400088560869'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5347040615161932801/posts/default/8170093400088560869'/><link rel='alternate' type='text/html' href='http://mvc2tips.blogspot.com/2010/03/passing-data-while-redirecting.html' title='Passing data while redirecting'/><author><name>jivangoyal</name><uri>http://www.blogger.com/profile/12853371042810428434</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>