<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Avivo Tech Blog &#187; view</title>
	<atom:link href="http://tech.avivo.si/tag/view/feed/" rel="self" type="application/rss+xml" />
	<link>http://tech.avivo.si</link>
	<description>Solving problems</description>
	<lastBuildDate>Tue, 24 Jan 2012 14:46:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>How to show compiler errors in ASP.NET MVC Views?</title>
		<link>http://tech.avivo.si/2011/02/how-to-show-compiler-errors-in-asp-net-mvc-views/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-show-compiler-errors-in-asp-net-mvc-views</link>
		<comments>http://tech.avivo.si/2011/02/how-to-show-compiler-errors-in-asp-net-mvc-views/#comments</comments>
		<pubDate>Mon, 07 Feb 2011 15:21:13 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[ascx]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[aspx]]></category>
		<category><![CDATA[compiler errors in asp.net mvc views]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[show error in aspx or ascx]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1195</guid>
		<description><![CDATA[Just open your csproj project file in notepad and find MvcBuildViews and set value to True. &#60;MvcBuildViews&#62;true&#60;/MvcBuildViews&#62;]]></description>
			<content:encoded><![CDATA[<p>Just open your <strong>csproj </strong>project file in notepad and find <strong>MvcBuildViews </strong>and set value to <strong>True</strong>.</p>
<pre class=xml>
&lt;MvcBuildViews&gt;true&lt;/MvcBuildViews&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2011/02/how-to-show-compiler-errors-in-asp-net-mvc-views/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP .NET MVC: How to render View into a string</title>
		<link>http://tech.avivo.si/2010/03/asp-net-mvc-how-to-render-view-into-a-string/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=asp-net-mvc-how-to-render-view-into-a-string</link>
		<comments>http://tech.avivo.si/2010/03/asp-net-mvc-how-to-render-view-into-a-string/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 21:38:36 +0000</pubDate>
		<dc:creator>developer</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Programming Techniques]]></category>
		<category><![CDATA[asp]]></category>
		<category><![CDATA[context]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[net]]></category>
		<category><![CDATA[Render]]></category>
		<category><![CDATA[render view to string in mvc]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[view]]></category>
		<category><![CDATA[view to html in mvc]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=472</guid>
		<description><![CDATA[Sometimes a developer needs to render a View as string. Practical scenario would be to create an obvious View and send it via e-mail instead displaying it in browser. Here is a simple way to extract content from a rendered View: Implement RenderViewToString method public class HomeController : Controller { protected string RenderViewToString(string viewName, object [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes a developer needs to render a View as string. Practical scenario would be to create an obvious View and send it via e-mail instead displaying it in browser. Here is a simple way to extract content from a rendered View:</p>
<p>Implement <em>RenderViewToString </em>method</p>
<pre class="c-sharp">public class HomeController : Controller
{
  protected string RenderViewToString(string viewName, object model)
  {
    string result = null;
    var view = ViewEngines.Engines.FindView(this.ControllerContext, viewName, null).View;
    if (view != null)
    {
      var sb = new StringBuilder();
      using (var writer = new StringWriter(sb))
      {
        var viewContext = new ViewContext(this.ControllerContext, view,
              new ViewDataDictionary(model), new TempDataDictionary(), writer);
        view.Render(viewContext, writer);
        writer.Flush();
      }
      result = sb.ToString();
    }
    return result;
  }
}</pre>
<p>Call it in your <em>action </em>method</p>
<pre class="c-sharp">//Somewhere in HomeController...
public ActionResult Index()
{
    //Render a View named 'Email' to string variable named 'content'
    //Second parameter (model) can be null
    string content = RenderViewToString("Email", new EmailModel());

    //Do something with the content, e.g. send it to e-mail

    //This does nothing to do with rendered string
    return View();
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2010/03/asp-net-mvc-how-to-render-view-into-a-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight: inherit a generic class from UserControl</title>
		<link>http://tech.avivo.si/2009/11/silverlight-inherit-a-generic-class-from-usercontrol/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=silverlight-inherit-a-generic-class-from-usercontrol</link>
		<comments>http://tech.avivo.si/2009/11/silverlight-inherit-a-generic-class-from-usercontrol/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 17:57:49 +0000</pubDate>
		<dc:creator>developer</dc:creator>
				<category><![CDATA[Programming Techniques]]></category>
		<category><![CDATA[Silverlight/WPF]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[derive]]></category>
		<category><![CDATA[generic]]></category>
		<category><![CDATA[inherit]]></category>
		<category><![CDATA[mvvm]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[UserControl]]></category>
		<category><![CDATA[view]]></category>
		<category><![CDATA[workaround]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=208</guid>
		<description><![CDATA[Note! This blog post is just an idea than well tested solution, more a review that detailed description. In Silverlight UserControl and Page classes are usually used with xaml. Root tags in xaml define the type, like so: xaml &#60;UserControl x:Class="MyView"&#62; ... &#60;/UserControl&#62; code-behind namespace MyNamespace { class MyView : UserControl } Sometimes, developers want [...]]]></description>
			<content:encoded><![CDATA[<p>Note! This blog post is just an idea than well tested solution, more a review that detailed description.<br />
In Silverlight UserControl and Page classes are usually used with xaml. Root tags in xaml define the type, like so:</p>
<pre class="c-sharp">xaml
&lt;UserControl x:Class="MyView"&gt;
...
&lt;/UserControl&gt;

code-behind
namespace MyNamespace
{
  class MyView : UserControl
}</pre>
<p>Sometimes, developers want to extend UserControl, i.e. as View by MVVM pattern.</p>
<pre class="c-sharp">xaml
&lt;v:ViewBase x:Class="MyNamespace.MyView" xmlns:v="clr-namespace:MyNamespace"&gt;
...
&lt;/v:ViewBase&gt;

code-behind
namespace MyNamespace
{
  class MyView : ViewBase /* ViewBase is a custom class */
}</pre>
<p>Step further, every View should have it&#8217;s specialized model (ViewModel), thus base class could integrate a Model property. To avoid casting one should use generics, like ViewBase&lt;MyViewModel&gt;.</p>
<pre class="c-sharp">xaml
&lt;!-- There's a problem, generics cannot be written in xaml. --&gt;

code-behind
namespace MyNamespace
{
  class MyView : ViewBase&lt;MyViewModel&gt; /* ViewBase is a custom class */
}</pre>
<p>Generics cannot be written directly in xaml? There is a workaround:<br />
1. Use a wrapper, described <a href="http://www.lab101.be/2008/07/silverlight-usercontrol-inheritance/">here</a><br />
2. Create a new non-generic class, like in this sample:</p>
<pre class="c-sharp">xaml
&lt;v:MyViewBase x:Class="MyNamespace.MyView" xmlns:v="clr-namespace:MyNamespace"&gt;
...
&lt;/v:MyViewBase&gt;

code-behind
namespace MyNamespace
{
  class MyView : MyViewBase
}

public abstract class MyViewBase : ViewBase&lt;MyViewModel&gt;
{
  /* non-generic class */
}</pre>
<p><strong>Appendix: ViewBase&lt;TViewModel&gt; class</strong></p>
<pre class="c-sharp">public abstract class ViewBase&lt;TViewModel&gt; : UserControl, INotifyPropertyChanged where TViewModel : ViewModelBase, new()
{
	private TViewModel model;
	public TViewModel Model
	{
		get
		{
			if (this.model == null)
			{
				this.model = new TViewModel();
				base.DataContext = this.model;
			}
			return this.model;
		}
		set
		{
			if (this.model != value)
			{
				this.model = value;
				base.DataContext = this.model;
				OnPropertyChanged("Model");
			}
		}
	}
}</pre>
<p>References:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/400778/usercontrol-that-has-a-generic-class-in-its-inheritance-tree">StackOverflow: UserControl that has a generic class in its inheritance tree</a></li>
<li><a href="http://stackoverflow.com/questions/225878/how-to-correctly-inherit-from-a-usercontrol-defined-in-xaml-in-silverlight">StackOverflow: How to correctly inherit from a UserControl defined in xaml in Silverlight</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2009/11/silverlight-inherit-a-generic-class-from-usercontrol/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

