<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>TechiesWeb</title>
	
	<link>http://www.techiesweb.net</link>
	<description>Tips &amp; Tricks on ASP.NET MVC, Ajax, jQuery, Entity Framework</description>
	<lastBuildDate>Sat, 09 Mar 2013 10:55:58 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/techiesweb" /><feedburner:info uri="techiesweb" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>techiesweb</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Pluggable ASP.NET MVC application project structure</title>
		<link>http://feedproxy.google.com/~r/techiesweb/~3/pDbm3n2g3aY/</link>
		<comments>http://www.techiesweb.net/pluggable-asp-net-mvc-application-project-structure/#comments</comments>
		<pubDate>Fri, 08 Feb 2013 02:28:36 +0000</pubDate>
		<dc:creator>Shyju</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[ASP.NET MVVC 4]]></category>
		<category><![CDATA[Loosely coupled]]></category>
		<category><![CDATA[modular programs]]></category>
		<category><![CDATA[Pluggable]]></category>
		<category><![CDATA[Pluggable ASP.NET MVC project structure]]></category>
		<category><![CDATA[plugin based development]]></category>

		<guid isPermaLink="false">http://www.techiesweb.net/?p=639</guid>
		<description><![CDATA[<p>Developing loosely coupled modular programs is a good idea because it eliminates the risk of recompilation. This way of development strategy lets you to create modules and deploy it without recompiling the entire project. You will have a main project and multiple modules on top of that. something similar to wordpress core and wordpress plugins does. Here i am [...]</p><p>The post <a href="http://www.techiesweb.net/pluggable-asp-net-mvc-application-project-structure/">Pluggable ASP.NET MVC application project structure</a> appeared first on <a href="http://www.techiesweb.net">TechiesWeb</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Developing loosely coupled modular programs is a good idea because it eliminates the risk of recompilation. This way of development strategy lets you to create modules and deploy it without recompiling the entire project. You will have a main project and multiple modules on top of that. something similar to wordpress core and wordpress plugins does. Here i am explaining,  how to develop a pluggable ASP.NET MVC application project structure.</p>
<h4><span style="font-size: 1em;">Step 1</span></h4>
<p>Create a new ASP.NET MVC Project.  This will be our core project and we will be adding different modules to this as needed.  You will see a project structure like this in your solution explorer. Since i opted for the &#8220;<strong>Empty</strong>&#8221; project template, the controllers folder is empty.</p>
<p style="text-align: center;"><a href="http://www.techiesweb.net/wp-content/uploads/2013/02/step1-create-core-project.png"><img class="size-full wp-image-640 aligncenter" alt="step1-create-core-project" src="http://www.techiesweb.net/wp-content/uploads/2013/02/step1-create-core-project.png" width="176" height="226" /></a></p>
<h4>Step 2</h4>
<p>Now let&#8217;s create a controller and it&#8217;s views to this project. I will add a &#8220;Home&#8221; controller and it&#8217;s &#8220;index&#8221; action and it&#8217;s view. I added some text to the <em>index.cshtm</em>l file and when i run the project, we can see the output like this.</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2013/02/step2-add-controller-and-view.png"><img class="alignnone size-full wp-image-643" alt="step2-add-controller-and-view" src="http://www.techiesweb.net/wp-content/uploads/2013/02/step2-add-controller-and-view.png" width="332" height="126" /></a></p>
<h4>Step 3</h4>
<p>Our next step is to create a folder for our modules. All of our modules are going to be an area on top of our main(Core) projecct.  So we will create a folder called &#8220;Areas&#8221; in the Core Project. I have also deleted the &#8220;<strong><em>Models</em></strong>&#8221; folder and &#8220;<em><strong>App_data</strong></em>&#8221; folder because we are not using that now.</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2013/02/step3-add-areas-folder.png"><img class="alignnone size-full wp-image-644" alt="step3-add-areas-folder" src="http://www.techiesweb.net/wp-content/uploads/2013/02/step3-add-areas-folder.png" width="192" height="206" /></a></p>
<p>Now if you check the physical location of our Core project, you will see the <em><strong>Areas</strong> </em>folder there. We will be using this as the location for our modules.</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2013/02/step3-areas-folder-in-project-location.png"><img class="alignnone size-full wp-image-645" alt="step3-areas-folder-in-project-location" src="http://www.techiesweb.net/wp-content/uploads/2013/02/step3-areas-folder-in-project-location.png" width="236" height="206" /></a></p>
<p>&nbsp;</p>
<h4>Step 4</h4>
<p>Now we will add our first module. Right click on the solution explorer and select <em><strong>Add-&gt;New Project</strong> </em>from the context menu. You will see the &#8220;Add New Project&#8221; dialog. Select &#8220;ASP.NET MVC4 Web application&#8221;. Specify the project name and <strong>s</strong><em><strong>elect the project location same as the path to our Areas folder</strong></em>.</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2013/02/step4-add-module-project.png"><img class="alignnone size-full wp-image-646" alt="step4-add-module-project" src="http://www.techiesweb.net/wp-content/uploads/2013/02/step4-add-module-project.png" width="539" height="310" /></a></p>
<p>&nbsp;</p>
<p>This will add the new project to our solution and it will be saved in the &#8220;<em><strong>Areas</strong></em>&#8221; folder of the main project. If you select the &#8220;Areas&#8221; folder in the main project and enable the &#8220;Show all files&#8221; option, you can see that our new project (Forum) is available under the <em><strong>Areas</strong> </em>folder.</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2013/02/step5-module-in-areas.png"><img class="aligncenter size-full wp-image-648" alt="step5-module-in-areas" src="http://www.techiesweb.net/wp-content/uploads/2013/02/step5-module-in-areas.png" width="205" height="418" /></a></p>
<h4>Step 6</h4>
<p>Our next step is to change the assembly output path location of our module project. Select the <em><strong>Forum</strong> </em>project, right click and select <em><strong>properties</strong> </em>from the context menu. Go to <em><strong>Build</strong> </em>tab. You will see a section called &#8220;<em><strong>Output</strong></em>&#8220;. There is a property called &#8220;Output path&#8221; Where you can define where the assemblies of this project should go when we build the project. By default the value will be <code>bin\\</code> . Change the value to <code>..\\..\\bin\\</code> so that it will drop the compiled assemblies to the <strong>bin</strong> folder of our main project (Core).</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2013/02/step6-set-output-path.png"><img class="aligncenter size-full wp-image-649" alt="step6-set-output-path" src="http://www.techiesweb.net/wp-content/uploads/2013/02/step6-set-output-path.png" width="461" height="114" /></a></p>
<h4>Step 7</h4>
<p>Now we will inherit the <em><strong>AreaRegistration</strong> </em>class and override some items from that. So Let&#8217;s add the below class to our module project.</p>
<pre class="brush:csharp">public class ForumAreaRegistration : AreaRegistration
{
    public override string AreaName
    {
        get { return "Forum";  }
    }
    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "forum_default",
            "Forum/{controller}/{action}/{id}",
            new { action = "Index", id = UrlParameter.Optional },
            namespaces: new string[] { "Forum.Controllers" }
        );
    }
}</pre>
<p>I will add this class to the <em><strong>App_Start</strong> </em>folder of the Forum Project. You can see that we overrode the <em><strong>AreaName</strong> </em>property and <em><strong>RegisterArea</strong> </em>method in this class. We have provided the area specific routing ( in this case Forum) in the <em><strong>RegisterArea</strong> </em>method.</p>
<p>You need to update the <em><strong>RegisterRoutes</strong> </em>method of Core project to include the namespace while defining routes. This  is to avoid the conflict between the controllers with same name which exists in both the projects.  So your route defenition (of core project) will looks like this</p>
<pre class="brush:csharp">public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
        namespaces: new string[] { "Core.Controllers" }
    );
}</pre>
<p>&nbsp;</p>
<p>Now build your Forum project and then run the main project. You may access the pages from core project and the module and see what it brings.</p>
<div id="attachment_651" class="wp-caption aligncenter" style="width: 319px"><a href="http://www.techiesweb.net/wp-content/uploads/2013/02/core-project-page.png"><img class="size-full wp-image-651" alt="Page of Core project" src="http://www.techiesweb.net/wp-content/uploads/2013/02/core-project-page.png" width="309" height="86" /></a><p class="wp-caption-text">Page of Core project</p></div>
<div id="attachment_652" class="wp-caption aligncenter" style="width: 373px"><a href="http://www.techiesweb.net/wp-content/uploads/2013/02/page-of-module.png"><img class="size-full wp-image-652" alt="Page from module" src="http://www.techiesweb.net/wp-content/uploads/2013/02/page-of-module.png" width="363" height="107" /></a><p class="wp-caption-text">Page from module</p></div>
<p>&nbsp;</p>
<p>The advantage of this pluggable architecture is, you can make some changes to one of your module and simply drop the assembly for that (and related view files if necessary) to the  bin folder of the main project.</p>
<p>The sample project i created for this blog post is available <a href="https://github.com/kshyju/PluggableMVC">here </a>for download. Enjoy. Do not forget to say “Hi” to me, if this post was useful to you.</p>
<p>The post <a href="http://www.techiesweb.net/pluggable-asp-net-mvc-application-project-structure/">Pluggable ASP.NET MVC application project structure</a> appeared first on <a href="http://www.techiesweb.net">TechiesWeb</a>.</p><img src="http://feeds.feedburner.com/~r/techiesweb/~4/pDbm3n2g3aY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techiesweb.net/pluggable-asp-net-mvc-application-project-structure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.techiesweb.net/pluggable-asp-net-mvc-application-project-structure/</feedburner:origLink></item>
		<item>
		<title>How you should not run a software project</title>
		<link>http://feedproxy.google.com/~r/techiesweb/~3/B19pU9CpNeI/</link>
		<comments>http://www.techiesweb.net/how-you-should-not-run-a-software-project/#comments</comments>
		<pubDate>Mon, 26 Nov 2012 21:22:41 +0000</pubDate>
		<dc:creator>Shyju</dc:creator>
				<category><![CDATA[Software development]]></category>
		<category><![CDATA[Bad practices]]></category>
		<category><![CDATA[Bad practices of developing software]]></category>
		<category><![CDATA[bad practices of software development]]></category>
		<category><![CDATA[project management]]></category>
		<category><![CDATA[software development process]]></category>
		<category><![CDATA[throughtput]]></category>

		<guid isPermaLink="false">http://www.techiesweb.net/?p=600</guid>
		<description><![CDATA[<p>I have been programming for a couple of years now. I worked in teams which delivered ERP level software as well as small team which delivered tiny projects. Other than my regular day job, i usually spend time writing code for my own hobby project(s). I devote time for reading tech blogs and follow a [...]</p><p>The post <a href="http://www.techiesweb.net/how-you-should-not-run-a-software-project/">How you should not run a software project</a> appeared first on <a href="http://www.techiesweb.net">TechiesWeb</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>I have been programming for a couple of years now. I worked in teams which delivered ERP level software as well as small team which delivered tiny projects. Other than my regular day job, i usually spend time writing code for my own hobby project(s). I devote time for reading tech blogs and follow a whole bunch of technical experts. The bottom line is, i believe myself that i know some part of this field, software engineering.</p>
<p>There are a lot of people / organizatoins doing software development. Some people doing it in the right way and some does not. I am going to point out some symptoms of  bad ways of developing software here. These are my personal thoughts and it could be absolutely wrong in another persons view. I don&#8217;t care what those people think and will definitely try to avoid doing the following  bad practices.</p>
<h2>Not Hiring a Designer for your UI/UX development.</h2>
<p>If you are not ready to hire a UI developer and you want to build great software, you are thinking it <strong>wrong</strong>.</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/11/developers-doing-design.png"><img class="alignright size-full wp-image-612" title="developers-doing-design" src="http://www.techiesweb.net/wp-content/uploads/2012/11/developers-doing-design.png" alt="" width="277" height="237" /></a></p>
<p>User interface obviously play a major role in keeping your end-user happy. It plays a significant role in your conversion rates as well. Nobody wants to use a screen which looks ugly or looks complex. Why did that happen ? because most of the time those were created by the normal developer!</p>
<p>If your company has a UX team, that is great. If not, you should hire someone temporarily who really does the UX job to get the base theme/layout of your app. This layout/theme should include sample pages( HTML &amp; CSS version) for all possible scenarios the app could use. Once the UX designing is done and approved by the upper layer, that should stay as the foundation of all future developments which the programmer does. the dev team lead /manager should make sure that his/her team is strictly following the template defined by the UX team. If there is a requirement to create some page element which was not defined in the base template, the developer should not simply add it himself (unless he is an equally talented designer himself, which is not very common). The request for this new page element should be routed to the UX team and they should handle that.</p>
<p>Remember, if your application is not providing a consistent look and feel, believe me, it is the worst thing. Never do that if you are serious about what you are doing!</p>
<h2>Not Providing the developer PC to your programmers</h2>
<p>I hate working with slow computers as you do. I loose all my enthusiasm and excitement of writing code if my machine hangs when i build my project.  It is quite frustrating.</p>
<p>You should make sure that your programmers are happy about their computers. It need not be the super computer in the office. But a fairly faster one where they should not feel that it is slow when they run whatever necessary apps they use  for their daily job. If your project is taking more than 6 second to build/rebuild, it is time for an upgrade.  If you are not providing a faster computer to them, you are not only making them frustrated, but bringing additional delay in your project. Remember hardware is much cheaper these days compared to the developer billing.</p>
<p>Faster computers increases productivity. There is  no question about that. If you are an employee and your employer does not understand this, it is time to switch your job.</p>
<h2>Reinventing the wheel</h2>
<p>This is a debatable point. Should you develop your own libraries when there are similar libraries exist which does a decent job ?. I would not do this unless i am developing such a library to really compete with the existing providers in the market.  What is the purpose of developing another logging framework yourself when log4net and Nlog exists ? These efforts usually ends up in creating a library which may not be perfect as the existing one. One added advantage of the existing libraries are , they are well tested -used by the developer community. so it is reliable.</p>
<p>Reinventing the wheel usually happens with people who are not aware of what is happening in the industry. They are not aware that there is an existing library exist and lot of people in the community is trusting it.  You don&#8217;t see them in any community activities.  They are not continuous learners, which is bad for your team.</p>
<h2>Creating a project plan which includes Weekends and Late nights</h2>
<p>If you are creating a project plan thinking that the developer will work in the weekends and late nights for the delivery,  you are not fit for this job. You are not realizing that the productivity will decrease as the developer works additional time. Jimmy bogard has written a nice <a href="http://lostechies.com/jimmybogard/2012/11/14/respect-and-the-40-hour-work-week/">article</a> about the 40 hour work culture. you should go and read it.</p>
<p>Remember, a good project manager should be able to mange his people too.</p>
<h2>Thinking that the newly hired fresher will deliver same as the experienced senior developer</h2>
<p>No!  Big No, is the answer. The newly hired employee can talk whatever he learned in the book and might have convinced you that he would fit for the (fresher) position during the hiring process.  But the knowledge, wisdom of what works better than other,  which the senior developer has acquired during his experience is totally different.  You can not replace that with a newly hired college graduate.</p>
<p>The bottom line is if you are hiring a fresher to replace a senior developer. You are doing it wrong!</p>
<p>&nbsp;</p>
<p>There are a lot of other miserable things happening in the software development process. These are the few which i came to my mind because unfortunately i happened to experience few of these during my career. Feel free to share your thoughts on this.</p>
<p>The post <a href="http://www.techiesweb.net/how-you-should-not-run-a-software-project/">How you should not run a software project</a> appeared first on <a href="http://www.techiesweb.net">TechiesWeb</a>.</p><img src="http://feeds.feedburner.com/~r/techiesweb/~4/B19pU9CpNeI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techiesweb.net/how-you-should-not-run-a-software-project/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.techiesweb.net/how-you-should-not-run-a-software-project/</feedburner:origLink></item>
		<item>
		<title>Rendering views from custom folders in ASP.NET MVC</title>
		<link>http://feedproxy.google.com/~r/techiesweb/~3/n9vh1cyMz1U/</link>
		<comments>http://www.techiesweb.net/rendering-views-from-custom-folders-in-asp-net-mvc/#comments</comments>
		<pubDate>Tue, 16 Oct 2012 19:24:17 +0000</pubDate>
		<dc:creator>Shyju</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[.cshtml location]]></category>
		<category><![CDATA[ASP.NET MVC views location]]></category>
		<category><![CDATA[Razor view location]]></category>
		<category><![CDATA[Rendering views from custom folders]]></category>
		<category><![CDATA[View location]]></category>
		<category><![CDATA[Views]]></category>
		<category><![CDATA[views from custom folders]]></category>

		<guid isPermaLink="false">http://www.techiesweb.net/?p=552</guid>
		<description><![CDATA[<p>ASP.NET MVC works with the concept of Convention over Configuration. that means, the programmer do not need to explicitly do many things and MVC will take care of those if he follows the conventions. One good example is, To return a view, you simply write one line Return View() and it will return the view [...]</p><p>The post <a href="http://www.techiesweb.net/rendering-views-from-custom-folders-in-asp-net-mvc/">Rendering views from custom folders in ASP.NET MVC</a> appeared first on <a href="http://www.techiesweb.net">TechiesWeb</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>ASP.NET MVC works with the concept of <strong>Convention over Configuration</strong>. that means, the programmer do not need to explicitly do many things and MVC will take care of those if he follows the conventions. One good example is, To return a view, you simply write one line <code>Return View()</code> and it will return the view from the appropriate directory ( assuming the programmer followed the convention and kept the view file in <strong>~/Views/<em>ThatControllerName</em>/</strong> folder with same name as of the action method. but MVC is extensible. If you want to override the convention. you can always do that. This post shows how rendering views from custom folders in asp.net mvc is possible.</p>
<p>By default, you will have a <strong>Views </strong>folder in root and you can have multiple folders under that with same name as of your controller name. Each of those folder will have views (<code>.cshtml</code> files) for your action methods. so the default structure will look like this for a controller called <code>CustomerController</code> with 3 action methods. <code>index</code>, <code>edit</code> and <code>details</code>.</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/10/action-methods.png"><img class="alignnone size-full wp-image-554" title="action methods" src="http://www.techiesweb.net/wp-content/uploads/2012/10/action-methods.png" alt="" width="430" height="280" /></a></p>
<p>View directory structure</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/10/default-view-convention.png"><img class="alignnone size-full wp-image-553" title="default-view-convention" src="http://www.techiesweb.net/wp-content/uploads/2012/10/default-view-convention.png" alt="" width="239" height="98" /></a></p>
<p>&nbsp;</p>
<h3>Returning view from a different location</h3>
<p>If you want to return a view from a different location, you can do it by specifying the full path to the view file when calling the <code>View</code> method. for example, if you want to return a view (index.cshtml) from a folder called <strong>Customer </strong>under <strong>UI</strong> folder which is in the root of the application,  you can do it like this</p>
<pre class="brush:csharp">public ActionResult Index()
{
    return View("~/UI/Customer/Index.cshtml");
}</pre>
<p>&nbsp;</p>
<p>Assuming you have the <strong> <em>_viewStart.html</em></strong> and <strong> <em>web.config </em></strong>present in your <strong>UI </strong>folder.</p>
<p>The above method works. but it is not a good solution to hardcode the location like this. What if we have a lots of controllers and action methods ? , are we going to hard code it like this ? No !!!</p>
<p>What we can do is we can extend the razor view engine and tell it to look for views in our custom location.  so if you look at the sourcecode of <code>RazorViewEngine</code>, you can see that the default  location (what the convention follows) is there.</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/10/razor-view-default-location.png"><img class="alignnone size-full wp-image-556" title="razor-view-default-location" src="http://www.techiesweb.net/wp-content/uploads/2012/10/razor-view-default-location.png" alt="" width="726" height="686" /></a></p>
<p>So let&#8217;s extend the <code>RazorViewEngine</code> and create our own view engine. Remember that we are going to simply change the View&#8217;s default location only. rest of the view functionality is going to be same (as of Razor). So we will create a class which extends from <code>RazorViewEngine</code> class and write code like this.</p>
<pre class="brush:csharp">public class MyCustomViewEngine : RazorViewEngine
{
    public MyCustomViewEngine()
    {
        string[] viewLocationFormatArr=new string[4];
        viewLocationFormatArr[0] = "~/UI/{1}/{0}.cshtml";
        viewLocationFormatArr[1] = "~/UI/{1}/{0}.vbhtml";
        viewLocationFormatArr[2] = "~/UI/Shared/{1}/{0}.vbhtml";
        viewLocationFormatArr[3] = "~/UI/Shared/{1}/{0}.vbhtml";
        this.ViewLocationFormats = viewLocationFormatArr;

        string[] masterLocationFormatArr = new string[4];
        masterLocationFormatArr[0] = "~/UI/{1}/{0}.cshtml";
        masterLocationFormatArr[1] = "~/UI/{1}/{0}.vbhtml";
        masterLocationFormatArr[2] = "~/UI/Shared/{1}/{0}.vbhtml";
        masterLocationFormatArr[3] = "~/UI/Shared/{1}/{0}.vbhtml";
        this.MasterLocationFormats = masterLocationFormatArr;

        string[] partialViewLocationFormatArr = new string[4];
        partialViewLocationFormatArr[0] = "~/UI/{1}/{0}.cshtml";
        partialViewLocationFormatArr[1] = "~/UI/{1}/{0}.vbhtml";
        partialViewLocationFormatArr[2] = "~/UI/Shared/{1}/{0}.vbhtml";
        partialViewLocationFormatArr[3] = "~/UI/Shared/{1}/{0}.vbhtml";
        this.ViewLocationFormats = partialViewLocationFormatArr;

    }
}</pre>
<p>Here i updated only the View related things. I did not update the other 3 properties which handles the location for Areas. But it is going to be the same way. You can simply mention the new folder name and it will be fine.</p>
<p><em><strong>RazorViewEngine</strong> class resides in <strong>System.Web.Mvc</strong> namespace which is in <strong>System.Web.Mvc</strong> dll</em></p>
<p>Now what we need to do is to register our new ViewEngine. So let&#8217;s go to the global.asax&#8217;s <code>Application_Start</code> event, clear existing view engines and register our new one.</p>
<pre class="brush:csharp">protected void Application_Start()
{
    ViewEngines.Engines.Clear();
    var ourViewEngine = new MyCustomViewEngine();
    ViewEngines.Engines.Add(ourViewEngine);

    AreaRegistration.RegisterAllAreas();

    WebApiConfig.Register(GlobalConfiguration.Configuration);
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}</pre>
<p>That is all you need to make it happen. Hit F5 and you can see your app is now bringing views from the <strong>UI </strong>folder, instead of the <strong>Views </strong>folder.</p>
<p>&nbsp;</p>
<p>You need to update the <strong>_viewStart.cshtml</strong><em> file to update the layout files location as well.</em></p>
<pre class="brush:csharp">@{
    Layout = "~/UI/Shared/_Layout.cshtml";
}</pre>
<p>Hope this helps. <a title="custom folders for views in asp.net mvc" href="http://www.techiesweb.net/wp-content/uploads/2012/10/CustomViewLocation.zip">Here</a> you can download a sample project which has the above approach implemented. Do not forget to say “Hi” to me, if this post was useful to you. <img src='http://www.techiesweb.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>&nbsp;</p>
<p>The post <a href="http://www.techiesweb.net/rendering-views-from-custom-folders-in-asp-net-mvc/">Rendering views from custom folders in ASP.NET MVC</a> appeared first on <a href="http://www.techiesweb.net">TechiesWeb</a>.</p><img src="http://feeds.feedburner.com/~r/techiesweb/~4/n9vh1cyMz1U" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techiesweb.net/rendering-views-from-custom-folders-in-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.techiesweb.net/rendering-views-from-custom-folders-in-asp-net-mvc/</feedburner:origLink></item>
		<item>
		<title>Radio button list in ASP.NET MVC</title>
		<link>http://feedproxy.google.com/~r/techiesweb/~3/zzatIUVffHk/</link>
		<comments>http://www.techiesweb.net/radio-button-list-in-asp-net-mvc/#comments</comments>
		<pubDate>Fri, 12 Oct 2012 02:54:21 +0000</pubDate>
		<dc:creator>Shyju</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Editor Template]]></category>
		<category><![CDATA[Form posting]]></category>
		<category><![CDATA[Html.EditorFor]]></category>
		<category><![CDATA[Radio button list]]></category>

		<guid isPermaLink="false">http://www.techiesweb.net/?p=517</guid>
		<description><![CDATA[<p>When developing web applications , you may need to show radio button list in ASP.NET MVC  so that users can make a selection from the options(radio buttons) and submit the form.  We can do this easily with the help of MVC Model binding. Let&#8217;s create a quiz page where we are going to show some questions [...]</p><p>The post <a href="http://www.techiesweb.net/radio-button-list-in-asp-net-mvc/">Radio button list in ASP.NET MVC</a> appeared first on <a href="http://www.techiesweb.net">TechiesWeb</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>When developing web applications , you may need to show radio button list in ASP.NET MVC  so that users can make a selection from the options(radio buttons) and submit the form.  We can do this easily with the help of MVC Model binding.</p>
<p>Let&#8217;s create a quiz page where we are going to show some questions with it&#8217;s answers to the user and user can select an answer from the available answer options, represented by radio buttons.</p>
<p>So first we will create some ViewModels for our view. ViewModel is nothing but a POCO class which we will use to transfer data between the action method and the view. So let&#8217;s create 3 classes like this.</p>
<p>&nbsp;</p>
<pre class="brush:csharp">public class Question
{
    public int ID { set; get; }
    public string QuestionText { set; get; }
    public List&lt;Answer&gt; Answers { set; get; }
    public string SelectedAnswer { set; get; }
    public Question()
    {
        Answers = new List&lt;Answer&gt;();
    }
}
public class Answer
{
    public int ID { set; get; }
    public string AnswerText { set; get; }
}
public class Evaluation
{
    public List&lt;Question&gt; Questions { set; get; }
    public Evaluation()
    {
        Questions = new List&lt;Question&gt;();
    }
}</pre>
<pre class="brush:csharp"></pre>
<p> Now,  in our GET action method for the view, we will create an object of our ViewModel (<code>Evaluation</code>) class and set the Questions and it&#8217;s Answers properties and then send that to the view by passing it to the View method.</p>
<pre class="brush:csharp">public ActionResult Index()
{
    var evalVM = new Evaluation();

    //the below is hardcoded for DEMO. you may get the data from some  
    //other place and set the questions and answers

    var q1 = new Question { ID = 1, QuestionText = "What is your favourite language" };
    q1.Answers.Add(new Answer { ID = 12, AnswerText = "PHP" });
    q1.Answers.Add(new Answer { ID = 13, AnswerText = "ASP.NET" });
    q1.Answers.Add(new Answer { ID = 14, AnswerText = "Java" });
    evalVM.Questions.Add(q1);

    var q2 = new Question { ID = 2, QuestionText = "What is your favourite DB" };
    q2.Answers.Add(new Answer { ID = 16, AnswerText = "SQL Server" });
    q2.Answers.Add(new Answer { ID = 17, AnswerText = "MyQL" });
    q2.Answers.Add(new Answer { ID = 18, AnswerText = "Oracle" });
    evalVM.Questions.Add(q2);

    return View(evalVM);           
}</pre>
<p>Now our next step is to create the views to render the UI.  We are going to create an editor template to render the questions and it&#8217;s answers. So Let&#8217;s go to the <code>Views</code> folder and create a folder called <strong>EditorTemplates</strong> under the current controller folder (if you added the GET action method to <code>Home</code> controller, this will be <code>~/Views/Home</code>)</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/10/mvc-editor-template-folder.png"><img class="alignnone size-full wp-image-520" title="mvc-editor-template-folder" alt="Editor template" src="http://www.techiesweb.net/wp-content/uploads/2012/10/mvc-editor-template-folder.png" width="320" height="180" /></a></p>
<p>After creating the folder, Add a new Editor template to that. Right click on the folder and select <strong>Add View</strong> option and give the name same as the type name (in this case<code> Question</code>).</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/10/editor-template.png"><img class="alignnone size-full wp-image-521" title="editor-template" alt="" src="http://www.techiesweb.net/wp-content/uploads/2012/10/editor-template.png" width="321" height="128" /></a></p>
<p>Now add the below code to the newly created editor template (Question.cshtml)</p>
<pre class="brush:csharp">@model ViewModels.Question
&lt;div&gt;
    @Html.HiddenFor(x=&gt;x.ID)
    &lt;h3&gt; @Model.QuestionText &lt;/h3&gt;
    @foreach (var a in Model.Answers)
    {
       &lt;p&gt;
          @Html.RadioButtonFor(b=&gt;b.SelectedAnswer,a.ID)  @a.AnswerText 
       &lt;/p&gt;
    }
&lt;/div&gt;</pre>
<p>What we are doing in the above code is, iterating through each Answers and showing a Radio button and the answer text. We are using the <code>RadioButtonFor</code> html helper method to render the radio button.</p>
<p>Now let&#8217;s  go to our main view (index.cshtml) and write some code. Our main view will be strongly typed to our <code>Evaluation</code> viewmodel and we will use the <code> <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.html.editorextensions.editorfor(VS.98).aspx" target="_blank">EditorFor</a></code> html helper method to bring our editor template to the main view(index.cshtml).</p>
<pre class="brush:csharp">@model ViewModels.Evaluation
&lt;h2&gt;Quiz 24&lt;/h2&gt;
@using (Html.BeginForm())
{
    @Html.EditorFor(x=&gt;x.Questions)
    &lt;input type="submit" /&gt;
}</pre>
<p>now run the app (hit F5) and you will see the screen with the questions and answers. each answer will be accompanied by a radio button so that user can select one.</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/10/asp.net-mvc-RadioButton-output.png"><img class="alignnone size-full wp-image-526" title="asp.net-mvc-RadioButton-output" alt="asp.net mvc radio button list values on form post" src="http://www.techiesweb.net/wp-content/uploads/2012/10/asp.net-mvc-RadioButton-output.png" width="448" height="328" /></a></p>
<h3>Getting the selected radio button values on form post</h3>
<p>To get the selected radio button values on form submit, we can check the properties of the posted model. MVC Model binding can bind the posted form data to an instance of our ViewModel. So let&#8217;s add the below code to handle the POST action method.</p>
<pre class="brush:csharp">[HttpPost]
public ActionResult Index(Evaluation model)
{
    if (ModelState.IsValid)
    {
        foreach (var q in model.Questions)
        {
            var qId = q.ID;
            var selectedAnswer = q.SelectedAnswer;
            // Save the data 
        }
        return RedirectToAction("ThankYou"); //PRG Pattern
    }
    //to do : reload questions and answers
    return View(model);
}</pre>
<p>Now if you run the program and use visual studio break points, you can see that the selected radio button values (AnswerID in our case) is available in the <code>SelectedAnswer</code> property of each question.</p>
<p>&nbsp;</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/10/radio-button-list-in-mvc-getting-selected-value.png"><img class="size-full wp-image-669 alignnone" alt="radio-button-list-in-mvc-getting-selected-value" src="http://www.techiesweb.net/wp-content/uploads/2012/10/radio-button-list-in-mvc-getting-selected-value.png" width="558" height="365" /></a></p>
<p>&nbsp;</p>
<p>Hope this helps. You can download the sample source code <a title="strongly typed radio button list in asp.net mvc" href="https://github.com/kshyju/ASP.MVC3-Radio-button-list">here</a>. Do not forget to say &#8220;Hi&#8221; to me,  if this post was useful to you.</p>
<p>&nbsp;</p>
<p>The post <a href="http://www.techiesweb.net/radio-button-list-in-asp-net-mvc/">Radio button list in ASP.NET MVC</a> appeared first on <a href="http://www.techiesweb.net">TechiesWeb</a>.</p><img src="http://feeds.feedburner.com/~r/techiesweb/~4/zzatIUVffHk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techiesweb.net/radio-button-list-in-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		<feedburner:origLink>http://www.techiesweb.net/radio-button-list-in-asp-net-mvc/</feedburner:origLink></item>
		<item>
		<title>Column Attribute in Entity Framework 5</title>
		<link>http://feedproxy.google.com/~r/techiesweb/~3/fOFymlaGiwM/</link>
		<comments>http://www.techiesweb.net/column-attribute-in-entity-framework-5/#comments</comments>
		<pubDate>Sat, 06 Oct 2012 11:14:29 +0000</pubDate>
		<dc:creator>Shyju</dc:creator>
				<category><![CDATA[codefirst]]></category>
		<category><![CDATA[EntityFramework]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[Column Attribute]]></category>
		<category><![CDATA[Column Data Annotation]]></category>
		<category><![CDATA[ColumnAttribute]]></category>
		<category><![CDATA[Entity Framework 4.3.1]]></category>
		<category><![CDATA[Entity Framework 5]]></category>
		<category><![CDATA[Entity Framework CodeFirst]]></category>

		<guid isPermaLink="false">http://www.techiesweb.net/?p=482</guid>
		<description><![CDATA[<p>When developing applications using Entity Framework code first approach, you may use Column data annotation on your model properties to define what attributes that property has, ex : name, type etc. in Entity Framework 4.3.1,  ColumnAttribute is defined in System.ComponentModel.DataAnnotations namespace which is available in EntityFramework.dll. So you need to add a reference to EntityFramework.dll and include a using [...]</p><p>The post <a href="http://www.techiesweb.net/column-attribute-in-entity-framework-5/">Column Attribute in Entity Framework 5</a> appeared first on <a href="http://www.techiesweb.net">TechiesWeb</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>When developing applications using Entity Framework code first approach, you may use <code>Column </code>data annotation on your model properties to define what attributes that property has, ex : name, type etc.</p>
<p>in Entity Framework 4.3.1,  ColumnAttribute is defined in <code>System.ComponentModel.DataAnnotations namespace</code> which is available in <code>EntityFramework.dll</code>. So you need to add a reference to EntityFramework.dll and include a <code>using</code> statement in your class to use that.</p>
<pre class="brush:csharp">using System.ComponentModel.DataAnnotations;
namespace YourProject.Models
{
    public class User
    {
        public int CustomerID { set; get; }

        [Column(TypeName = "ntext")]
        public string AboutText { get; set; }
    }
}</pre>
<p>&nbsp;</p>
<p>But in EntityFramework 5, If you use the same code, you will get a compile time error like below</p>
<p><code><em><strong>The type or namespace name 'ColumnAttribute' could not be found (are you missing a using directive or an assembly reference?)</strong></em></code></p>
<p>The reason for this error is, in  Entity Framework 5, they moved the <code>ColumnAttribute</code> class to a different namespace called <code>System.ComponentModel.DataAnnotations.Schema</code>. So you need to add a <code>using</code> statement to include that namespace too in your model class.</p>
<pre class="brush:csharp">using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace YourProject.Models
{
    public class User
    {
        public int CustomerID { set; get; }

        [Column(TypeName = "ntext")]
        public string AboutText { get; set; }
    }
}</pre>
<pre class="brush:csharp"></pre>
<p>People usually get this error, when they follow a book which has sample code which uses Entity Framework 4.3.1 and they try to create the project and download Entity Framework via nuget where they will get the latest version, Entity framework 5 ( at the time of this post). Adding the relevant namespace will fix the issue.</p>
<p>More info in msdn,</p>
<p><a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.schema.columnattribute.aspx">ColumnAttribute class</a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.schema.aspx">System.ComponentModel.DataAnnotations.Schema Namespace</a></p>
<p>If interested, you can see the source code by checking the class in any assembly decompiling tools.</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/10/ColumnAttrinuteInEntityFramework5.png"><img class="alignnone size-full wp-image-485" title="ColumnAttrinuteInEntityFramework5" src="http://www.techiesweb.net/wp-content/uploads/2012/10/ColumnAttrinuteInEntityFramework5.png" alt="ColumnAttribute in EntityFramework 5" width="521" height="355" /></a></p>
<p>&nbsp;</p>
<p>The post <a href="http://www.techiesweb.net/column-attribute-in-entity-framework-5/">Column Attribute in Entity Framework 5</a> appeared first on <a href="http://www.techiesweb.net">TechiesWeb</a>.</p><img src="http://feeds.feedburner.com/~r/techiesweb/~4/fOFymlaGiwM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techiesweb.net/column-attribute-in-entity-framework-5/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.techiesweb.net/column-attribute-in-entity-framework-5/</feedburner:origLink></item>
		<item>
		<title>TechiesWebMetro wordpress theme</title>
		<link>http://feedproxy.google.com/~r/techiesweb/~3/G1gA4utc9Y4/</link>
		<comments>http://www.techiesweb.net/techieswebmetro-wordpress-theme/#comments</comments>
		<pubDate>Tue, 02 Oct 2012 20:04:05 +0000</pubDate>
		<dc:creator>Shyju</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[custom wordpress theme]]></category>
		<category><![CDATA[TechiesWeb Metro wordpress theme]]></category>
		<category><![CDATA[TechiesWebMetro]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress theme]]></category>

		<guid isPermaLink="false">http://www.techiesweb.net/?p=473</guid>
		<description><![CDATA[<p>I created a new wordpress theme and thought of sharing back to the community . I was not doing any kind of wordpress stuff for the past 2-3 years, but  happened to attend the wonderful ann arbor give camp this year where our team did some wordpress customization(which includes a custom theme creation) for the non-profit [...]</p><p>The post <a href="http://www.techiesweb.net/techieswebmetro-wordpress-theme/">TechiesWebMetro wordpress theme</a> appeared first on <a href="http://www.techiesweb.net">TechiesWeb</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>I created a new wordpress theme and thought of sharing back to the community <img src='http://www.techiesweb.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  .</p>
<p>I was not doing any kind of wordpress stuff for the past 2-3 years, but  happened to attend the wonderful <a href="http://annarborgivecamp.org/">ann arbor give camp</a> this year where our team did some wordpress customization(which includes a custom theme creation) for the non-profit organization <a href="http://www.enlighten.com/2012/09/hacking-for-charity/">we were working with.</a> This made me think about creating a new theme and i jumped in!</p>
<p>This theme is developed on top of StudioPress theme from <a href="http://www.dailyblogtips.com/studiopress-wordpress-theme-released/">dailyblogtips</a>.  My special thanks to them. <img src='http://www.techiesweb.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I named the theme as &#8220;TechiesWebMetro&#8221;.  Hope you like it.</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/10/TechiesWebMetroTheme.png"><img class="alignnone size-full wp-image-475" title="TechiesWebMetroTheme" src="http://www.techiesweb.net/wp-content/uploads/2012/10/TechiesWebMetroTheme.png" alt="TechiesWebMetro WordPress theme" width="589" height="403" /></a></p>
<p>I updated this blog to my new theme. So you must be <strong>feeling</strong> the new theme now <img src='http://www.techiesweb.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>You can download the  theme <a title="TechiesWebMetro wordpress theme" href="http://www.techiesweb.net/wp-content/uploads/2012/10/techieswebmetro.zip">here</a>.</p>
<p>The post <a href="http://www.techiesweb.net/techieswebmetro-wordpress-theme/">TechiesWebMetro wordpress theme</a> appeared first on <a href="http://www.techiesweb.net">TechiesWeb</a>.</p><img src="http://feeds.feedburner.com/~r/techiesweb/~4/G1gA4utc9Y4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techiesweb.net/techieswebmetro-wordpress-theme/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.techiesweb.net/techieswebmetro-wordpress-theme/</feedburner:origLink></item>
		<item>
		<title>ASP.NET MVC3 Tree View with jsTree</title>
		<link>http://feedproxy.google.com/~r/techiesweb/~3/itT0789sD8Y/</link>
		<comments>http://www.techiesweb.net/asp-net-mvc3-tree-view-with-jstree/#comments</comments>
		<pubDate>Fri, 21 Sep 2012 14:39:49 +0000</pubDate>
		<dc:creator>Shyju</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[ASP.NET MVC TreeView]]></category>
		<category><![CDATA[Hierarchical tree]]></category>
		<category><![CDATA[jsTree]]></category>
		<category><![CDATA[MVC jsTree]]></category>
		<category><![CDATA[MVC TreeView]]></category>
		<category><![CDATA[Organization Tree]]></category>
		<category><![CDATA[SqlCE]]></category>
		<category><![CDATA[SqlServer Compact]]></category>
		<category><![CDATA[TreeView]]></category>

		<guid isPermaLink="false">http://www.techiesweb.net/?p=433</guid>
		<description><![CDATA[<p>In ASP.NET MVC, There is no server controls like what we have in Web forms to render TreeView/ Menu, We need to write our own markup to do so. Even in all those webforms controls, it is generating some HTML which renders a tree or a menu. Here we are going to create an ASP.NET MVC3 Tree [...]</p><p>The post <a href="http://www.techiesweb.net/asp-net-mvc3-tree-view-with-jstree/">ASP.NET MVC3 Tree View with jsTree</a> appeared first on <a href="http://www.techiesweb.net">TechiesWeb</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>In ASP.NET MVC, There is<strong> no server controls</strong> like what we have in Web forms to render TreeView/ Menu, We need to write our own markup to do so. Even in all those webforms controls, it is generating some HTML which renders a tree or a menu. Here we are going to create an ASP.NET MVC3 Tree View with jsTree plugin.</p>
<h2>MVC3 Tree View with jsTree</h2>
<p>We will be creating an organizational tree which shows a hierarchical representation of who works for whom in an organization. We will have a table which stores the employee information along with who their manager is like below. I used SQL Server Compact Edition database in this project to store our data. To render the tree,  we are using <a href="https://github.com/vakata/jstree">jsTree</a> plugin which converts our ul-li elements to a tree structure.</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/09/org-table-data.png"><img class="alignnone size-full wp-image-435" title="org-table-data" src="http://www.techiesweb.net/wp-content/uploads/2012/09/org-table-data.png" alt="mvc3 tree view" width="311" height="179" /></a></p>
<p>Each Employee record has a <code>ManagerID</code> which tells who is the manager of that employee. I set the First employee&#8217;s ManagerID value as <code>NULL</code>, because he is the President of the company and he do not have any manager.</p>
<p>Now, Let&#8217;s create a model to represent the employee. we will create a POCO Class like this.</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/09/Employee-model.png"><img class="alignnone size-full wp-image-441" title="Employee-model" src="http://www.techiesweb.net/wp-content/uploads/2012/09/Employee-model.png" alt="model for mvc3 tree view" width="499" height="238" /></a></p>
<p>&nbsp;</p>
<p>Now we need a data access method to read data from our SQLServer compact database and return a list of  UserViewModel object. Since my demo program stores table in SQL Server compact edition database, i am using <code>SqlCeConnection</code> class and <code>SqlCeCommand</code> class to talk to it and get data.These two classes belongs to <code>System.Data.SqlServerCe</code> namespace. You need to add a using statement to import this namespace to your data access class.</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/09/Data-Access-with-SqlServerCompactEdition1.png"><img class="alignnone size-full wp-image-442" title="Data-Access-with-SqlServerCompactEdition" src="http://www.techiesweb.net/wp-content/uploads/2012/09/Data-Access-with-SqlServerCompactEdition1.png" alt="" width="820" height="628" /></a></p>
<p>&nbsp;</p>
<p>So <code>GetAllUsers</code> method with give us a list of User class objects</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/09/list-of-employee-objects.png"><img class="alignnone size-full wp-image-443" title="list-of-employee-objects" src="http://www.techiesweb.net/wp-content/uploads/2012/09/list-of-employee-objects.png" alt="" width="387" height="169" /></a></p>
<p>Now we need to convert this list of objects (which is  a sequential list) to hierarchical form. that means, All the employees belongs to Joe, should be listed in his Employees property. So Let&#8217;s do some tricky code here to change the sequential list to hierarchical structure. So Let&#8217;s do that in our action method.</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/09/action-method.png"><img class="alignnone size-full wp-image-444" title="action-method" src="http://www.techiesweb.net/wp-content/uploads/2012/09/action-method.png" alt="hierarchical objects for mvc3 tree view" width="656" height="519" /></a></p>
<p>You can see that we are getting a list of Employee objects using our data access method and then getting the president of the company who does not have any manager so that we can show him as the first /top node of the organization tree.(Assuming that we will have only one president). We are getting the user object which has a null value for the ManagerID column as the president.</p>
<h3>Setting the child objects.</h3>
<p>After getting the president node, We are going to call SetChildren method which accepts an  Employee Model and the List of Total Users/Employees and then finding out the children / Employees reports to this employee. We are  doing recursion to set the children because we do not know how many layers of employees will be there in the hierarchy. Recursively calling the SetChildren function will set the child Employees for all the employees and at the end of that we will be getting a single Employee object with Children property properly filled.</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/09/ORganization-tree-1.png"><img class="alignnone size-full wp-image-445" title="ORganization-tree-1" src="http://www.techiesweb.net/wp-content/uploads/2012/09/ORganization-tree-1.png" alt="" width="428" height="136" /></a></p>
<p>And if you expand the Employees property further you can see the employees works under this employee.</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/09/ORganization-tree-expanded.png"><img class="alignnone size-full wp-image-446" title="ORganization-tree-expanded" src="http://www.techiesweb.net/wp-content/uploads/2012/09/ORganization-tree-expanded.png" alt="" width="448" height="254" /></a></p>
<p>Now let&#8217;s update our view to have the sufficient markup to render the tree. Since we are using  jsTree, We need to include jsTree library to the page. I included the default css file also. I updated the css file to show a user  icon instead of showing the default directory icon.</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/09/strongly-typed-razor-view.png"><img class="alignnone size-full wp-image-448" title="strongly-typed-razor-view" src="http://www.techiesweb.net/wp-content/uploads/2012/09/strongly-typed-razor-view.png" alt="" width="668" height="462" /></a></p>
<p>Our view is strongly typed to Employee class, which will be representing the president / top node of the hierarchy.  After printing the Name property value of the first node, We are calling a partial view called Children and passing our Model to that. So i created a partial view called <code>Children.cshtml</code> under the same view folder and have markup like this</p>
<p>&nbsp;</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/09/ChildrenView.png"><img class="alignnone size-full wp-image-449" title="ChildrenView" src="http://www.techiesweb.net/wp-content/uploads/2012/09/ChildrenView.png" alt="" width="485" height="314" /></a></p>
<p>You can see recursion here also. We are calling the Childrens partial view recursively to render the child&#8217;s for each node.</p>
<p>Now let&#8217;s see how  it works when you run the project.</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/09/asp.net-mvc-treeview-output.png"><img class="alignnone size-full wp-image-451" title="asp.net-mvc-treeview-output" src="http://www.techiesweb.net/wp-content/uploads/2012/09/asp.net-mvc-treeview-output.png" alt="" width="283" height="235" /></a></p>
<p>You can customize the tree look and feel by changing the css  or playing with the options of  <a href="http://www.jstree.com/demo">jsTree</a>. You can download a working sample which i created to write this post <a href="http://www.techiesweb.net/wp-content/uploads/2012/09/ASP.NET-MVC3-TreeView-with-js-tree.rar">here</a>.</p>
<p>Hope this helps. Do not forget to leave a comment, if this post was useful to you. <img src='http://www.techiesweb.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>&nbsp;</p>
<p><span style="color: #ffffff;"> NSUGX3J7C2U3</span></p>
<p>&nbsp;</p>
<p>The post <a href="http://www.techiesweb.net/asp-net-mvc3-tree-view-with-jstree/">ASP.NET MVC3 Tree View with jsTree</a> appeared first on <a href="http://www.techiesweb.net">TechiesWeb</a>.</p><img src="http://feeds.feedburner.com/~r/techiesweb/~4/itT0789sD8Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techiesweb.net/asp-net-mvc3-tree-view-with-jstree/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		<feedburner:origLink>http://www.techiesweb.net/asp-net-mvc3-tree-view-with-jstree/</feedburner:origLink></item>
		<item>
		<title>ASP.NET MVC3 Dynamically added form fields model binding</title>
		<link>http://feedproxy.google.com/~r/techiesweb/~3/zhNFP3a3xxI/</link>
		<comments>http://www.techiesweb.net/asp-net-mvc3-dynamically-added-form-fields-model-binding/#comments</comments>
		<pubDate>Mon, 17 Sep 2012 19:57:49 +0000</pubDate>
		<dc:creator>Shyju</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[asp.net mvc3]]></category>
		<category><![CDATA[asp.net mvc3 dynamic field model binding]]></category>
		<category><![CDATA[asp.net mvc3 dynamic form]]></category>
		<category><![CDATA[asp.net mvc3 model binding]]></category>
		<category><![CDATA[inline editing]]></category>
		<category><![CDATA[mvc3 dynamic forms]]></category>

		<guid isPermaLink="false">http://www.techiesweb.net/?p=357</guid>
		<description><![CDATA[<p>Adding  new Item to a list of items, inline is a very nice feature you can provide to your user. This posts shows 2 different ways to do this in ASP.NET MVC3 and how Modelbinding handles that. MVC3 dynamically added form fields model binding We are going to create a new page where it lists [...]</p><p>The post <a href="http://www.techiesweb.net/asp-net-mvc3-dynamically-added-form-fields-model-binding/">ASP.NET MVC3 Dynamically added form fields model binding</a> appeared first on <a href="http://www.techiesweb.net">TechiesWeb</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Adding  new Item to a list of items, inline is a very nice feature you can provide to your user. This posts shows 2 different ways to do this in ASP.NET MVC3 and how Modelbinding handles that.</p>
<h2>MVC3 dynamically added form fields model binding</h2>
<p>We are going to create a new page where it lists the various Programming Interests a user has.  The user will have an option to add a new Record ( Programming interest) to the list present.</p>
<p>Let&#8217;s create 2 ViewModels(ViewModel is a simple POCO class) for our views. Add the below 2 classes to our project.</p>
<pre class="brush:csharp">public class User
{
    public int Id { set; get; }
    public string Name { get; set; }   
    public IList&lt;UserInterest&gt; Interests { get; set; }
}
public class UserInterest
{
    public int Id { set; get; }
    public string InterestText { set; get; }
    public bool IsExperienced { set; get; }
}</pre>
<p>Now I am going to create a <code>GET</code> action which returns a <code>User</code> class object with his interests.</p>
<pre class="brush:csharp">public ActionResult ClientSideCreation()
{
    var usr = new User();
    usr.Name = "Jon Skeet";
    usr.Interests = GetUserInterests();
    return View(usr);
}</pre>
<p>This action is simply creating an object and setting the Name property and Setting the Interests collection. <code>GetUserInterests</code> is a method which returns a list of <code>UserInterest</code> object.</p>
<p>Now to handle the collection Property of our Model, Let&#8217;s create an <strong>Editor template</strong> called  <code>UserInterest.cshtml</code> under <code>Home\EditorTempaltes</code>.</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/09/editor-template.png"><img class="size-full wp-image-360" title="editor-template" src="http://www.techiesweb.net/wp-content/uploads/2012/09/editor-template.png" alt="Editor Template" width="292" height="83" /></a></p>
<p>Now we will use <code>Html.EditorFor</code> HTML Helper method to bring this editor template to our main view.</p>
<pre class="brush:csharp">@model MvcApplication2.Models.User
@using(Html.BeginForm())
{ 
 &lt;h3&gt;Name : @Model.Name&lt;/h3&gt;
 &lt;h4&gt;Interests&lt;/h4&gt;   
 &lt;div class="divIntersts"&gt;
    &lt;table  id="container"&gt;
     &lt;tr&gt;
        &lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Have Experience?&lt;/th&gt;
     &lt;/tr&gt;
     @Html.EditorFor(x =&gt; x.Interests)    
    &lt;/table&gt;   
 &lt;/div&gt;
 &lt;p&gt;&lt;input type="submit" value="Save" /&gt;&lt;/p&gt;
}</pre>
<p>We are done with that. Running the project will show the output like this.<br />
<a href="http://www.techiesweb.net/wp-content/uploads/2012/09/editor-template-view-rendered.png"><img class="alignnone size-full wp-image-364" title="editor-template-view-rendered" src="http://www.techiesweb.net/wp-content/uploads/2012/09/editor-template-view-rendered.png" alt="EditorTemplate showing a collection of Items" width="353" height="214" /></a></p>
<p>note that this does not have any feature for the user to add the new record to the collection.</p>
<h2>Adding Record Inline</h2>
<p>I am going to make some changes to our view.</p>
<p><strong>1) </strong>Add a button called &#8221; <em><strong>Add new Item </strong></em>&#8221; to our html markup.</p>
<pre>&lt;input type="button" id="btnAdd" value="Add New Item" /&gt;</pre>
<p><strong>2)</strong> Add some javascript code to create the form fields when user clicks on the <em><strong>Add New Item</strong></em> button and append that to our table which holds the collection.</p>
<pre class="brush:js">    $(function () {
        $("#btnAdd").click(function (e) {
            var itemIndex = $("#container input.iHidden").length;
            e.preventDefault();
            var newItem = $("&lt;tr&gt;&lt;td&gt;&lt;input id='Interests_" + itemIndex + "__Id' type='hidden' value='' class='iHidden'  name='Interests[" + itemIndex + "].Id' /&gt;&lt;input type='text' id='Interests_" + itemIndex + "__InterestText' name='Interests[" + itemIndex + "].InterestText'/&gt;&lt;/td&gt;&lt;td&gt;&lt;input type='checkbox' value='true'  id='Interests_" + itemIndex + "__IsExperienced' name='Interests[" + itemIndex + "].IsExperienced' /&gt;&lt;/tr&gt;");
            $("#container").append(newItem);
        });
    });</pre>
<p>So the result of running our updated project will be like this. there is a &#8220;<em><strong>Add New Item</strong></em>&#8221; button and clicking that will add new record to our existing table.<br />
<a href="http://www.techiesweb.net/wp-content/uploads/2012/09/newItem-added1.png"><img class="alignnone size-full wp-image-380" title="newItem-added" src="http://www.techiesweb.net/wp-content/uploads/2012/09/newItem-added1.png" alt="" width="327" height="180" /></a></p>
<p>Now When the user posts the form, the MVC Model binding feature will bind the newly added items as well. You can check that by putting a breakpoint in the HttpPost action method.</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/09/httpposted.png"><img class="alignnone size-full wp-image-373" title="httpposted" src="http://www.techiesweb.net/wp-content/uploads/2012/09/httpposted.png" alt="" width="692" height="220" /></a></p>
<p>&nbsp;</p>
<p>The trick is to keep the <strong>id</strong> property value of the html element in this format.</p>
<p><code>CollectionName_<em>ItemIndex</em>__PropertyName</code></p>
<p>and <strong>name</strong> property value in this format</p>
<p><code>CollectionName[<em>ItemIndex</em>].PropertyName</code></p>
<p>If your Collection item has many fields, It will be hard to write javascript code for creating the form elements. In that case, You may consider doing it in the server side.</p>
<p>So i will update my javascript code like this.</p>
<pre class="brush:js">$(function () {
    $("#btnAdd").click(function (e) {
        var itemIndex = $("#container input.iHidden").length;       
        e.preventDefault();
        $.get("@Url.Action("NewInterestRow", "Home")/"+itemIndex,function(data){
            $("#container").append(data);
        });           
    });
});</pre>
<p>You can see that we are not building the html in our client side code here. Instead we are mkaing an ajax call to the <code>NewInterestRow</code> action method and passing the Index of the new item. So we need to create that action method like this.</p>
<pre class="brush:csharp">public ActionResult NewInterestRow(int id)
{
    var interest = new UserInterest { Id=id};
    return View("Partial/NewInterestRow",interest);
}</pre>
<p>&nbsp;</p>
<p>It simply creates an object of our <code>UserInterest</code> class and set the <code>Id</code>  property value of it as the values passed to this method (which is the Item Index of the new item to be created) .Then we are passing that object to a partial view called <code>NewInterestRow</code>. So Lets create a new View under <code>Home/Partial</code> called <code>NewInterestRow.cshtml</code> with the below content.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<pre class="brush:csharp">@model MvcApplication2.Models.UserInterest
@{    Layout = null; }
&lt;tr&gt; 
 &lt;td&gt;
  &lt;input type="hidden" id="Interests_@(Model.Id)__Id" class="iHidden"  name='Interests[@Model.Id].Id' /&gt;
  &lt;input type='text' id='Interests_@(Model.Id)__InterestText'   name='Interests[@Model.Id].InterestText'/&gt;
 &lt;/td&gt;
 &lt;td&gt;
    &lt;input type='checkbox' value='true'  id='Interests_@(Model.Id)__IsExperienced' name='Interests[@Model.Id].IsExperienced' /&gt;
 &lt;/td&gt;
&lt;/tr&gt;</pre>
<p>This View also creates the same HTML elements we created at client side previously, with the same name /ID convention we need for the Model binding to work.</p>
<p>&nbsp;</p>
<p><strong>Summary :</strong> Here we showed 2 ways to add dynamic form fields to an existing collection which gives a nice user experience and how MVC Model binding works for those new elements. The main thing to remember is to keep the format of the <strong>name</strong> and <strong>id</strong> property values. Model binding will work for the new elements only if they follow the format.</p>
<p>You can download the sample source code <a href="http://www.techiesweb.net/wp-content/uploads/2012/09/DynamicForm.rar">here</a> to see how it works.</p>
<p>&nbsp;</p>
<p>The post <a href="http://www.techiesweb.net/asp-net-mvc3-dynamically-added-form-fields-model-binding/">ASP.NET MVC3 Dynamically added form fields model binding</a> appeared first on <a href="http://www.techiesweb.net">TechiesWeb</a>.</p><img src="http://feeds.feedburner.com/~r/techiesweb/~4/zhNFP3a3xxI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techiesweb.net/asp-net-mvc3-dynamically-added-form-fields-model-binding/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		<feedburner:origLink>http://www.techiesweb.net/asp-net-mvc3-dynamically-added-form-fields-model-binding/</feedburner:origLink></item>
		<item>
		<title>ASP.NET MVC How to get Model Error details in Controller Action Method When ModelValidation fails</title>
		<link>http://feedproxy.google.com/~r/techiesweb/~3/dyZDs61N8X4/</link>
		<comments>http://www.techiesweb.net/asp-net-mvc-how-to-get-model-error-details-in-controller-action-method-when-modelvalidation-fails/#comments</comments>
		<pubDate>Tue, 11 Sep 2012 23:29:55 +0000</pubDate>
		<dc:creator>Shyju</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[ASO.NET MVC3]]></category>
		<category><![CDATA[IsValid]]></category>
		<category><![CDATA[model error]]></category>
		<category><![CDATA[ModelState]]></category>
		<category><![CDATA[ModelValidation]]></category>

		<guid isPermaLink="false">http://www.techiesweb.net/?p=346</guid>
		<description><![CDATA[<p>When Working with MVC Model Validations, You may come across a situation where you think you filled all the Required Items in the Form and submitted, but still the ModelState.IsValid property is returning false. I came across this scenario once when i was inherting  a ViewModel from another ViewModel. How do we know what is [...]</p><p>The post <a href="http://www.techiesweb.net/asp-net-mvc-how-to-get-model-error-details-in-controller-action-method-when-modelvalidation-fails/">ASP.NET MVC How to get Model Error details in Controller Action Method When ModelValidation fails</a> appeared first on <a href="http://www.techiesweb.net">TechiesWeb</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>When Working with MVC Model Validations, You may come across a situation where you think you filled all the Required Items in the Form and submitted, but still the <code>ModelState.IsValid</code> property is returning false. I came across this scenario once when i was inherting  a ViewModel from another ViewModel. How do we know what is causing the IsValid property to return false ?</p>
<p>You can check the <code>ViewData.ModelState.Values</code> collection and see what are the Errors. Here is the sample code</p>
<p>&nbsp;</p>
<pre class="brush:csharp">[Httpost]
public ActionResult Create(User model)
{
   if(ModelState.IsValid)
   {
     //Save and redirect
   }
   else
   {
     foreach (var modelStateVal in ViewData.ModelState.Values)
     {
       foreach (var error in modelStateVal.Errors)
       {               
          var errorMessage = error.ErrorMessage;
          var exception = error.Exception;
          // You may log the errors if you want
       }
     }
   }         
   return View(model);
 }
}</pre>
<p>&nbsp;</p>
<p>The post <a href="http://www.techiesweb.net/asp-net-mvc-how-to-get-model-error-details-in-controller-action-method-when-modelvalidation-fails/">ASP.NET MVC How to get Model Error details in Controller Action Method When ModelValidation fails</a> appeared first on <a href="http://www.techiesweb.net">TechiesWeb</a>.</p><img src="http://feeds.feedburner.com/~r/techiesweb/~4/dyZDs61N8X4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techiesweb.net/asp-net-mvc-how-to-get-model-error-details-in-controller-action-method-when-modelvalidation-fails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.techiesweb.net/asp-net-mvc-how-to-get-model-error-details-in-controller-action-method-when-modelvalidation-fails/</feedburner:origLink></item>
		<item>
		<title>How to Convert DataTable to Collection of Custom Class object</title>
		<link>http://feedproxy.google.com/~r/techiesweb/~3/t74BuRYjOXw/</link>
		<comments>http://www.techiesweb.net/how-to-convert-datatable-to-collection-of-custom-class-object/#comments</comments>
		<pubDate>Wed, 15 Aug 2012 18:20:10 +0000</pubDate>
		<dc:creator>Shyju</dc:creator>
				<category><![CDATA[C# 4.0]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[AsEnumerable]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[DataTable]]></category>

		<guid isPermaLink="false">http://www.techiesweb.net/?p=325</guid>
		<description><![CDATA[<p>Imagine you have a DataTable with Records and you want to Convert that to a List of your Custom class objects ? how do you do that ? The normal -straight forward way is to Loop through  each DataRow, Create a new instance of Custom class object, read the column values of the current row(iterator) [...]</p><p>The post <a href="http://www.techiesweb.net/how-to-convert-datatable-to-collection-of-custom-class-object/">How to Convert DataTable to Collection of Custom Class object</a> appeared first on <a href="http://www.techiesweb.net">TechiesWeb</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Imagine you have a <code>DataTable</code> with Records and you want to Convert that to a List of your Custom class objects ? how do you do that ?</p>
<p>The normal -straight forward way is to Loop through  each <code>DataRow</code>, Create a new instance of Custom class object, read the column values of the current row(iterator) in the loop and Set the Proerties of the object..</p>
<p>The below code shows looping the DataRows and Creating an object of our Custom Customer Class and Setting the Properties and Adding to the Collection of Customer objects.</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/08/for-each-datatable.png"><img class="alignnone size-full wp-image-326" title="for-each-datatable" src="http://www.techiesweb.net/wp-content/uploads/2012/08/for-each-datatable.png" alt="" width="567" height="293" /></a></p>
<p>We can avoid this handwritten ForEach loop by using some <strong>LINQ</strong> syntax.  Generally LINQ queries works on data sources which implement the <code>IEnumerable</code>&lt;T&gt;/ <code>IQueryable</code>&lt;T&gt; Interface. But DataTable does not implement any of these. So we can not directly apply LINQ queries on a DataTable.</p>
<p>But <code>DataTable</code> class has an extension method called <code>AsEnumerable</code> which returns an IEnumerable collection of DataRow. So we can apply the <code>AsEnumerable</code> function on a <code>DataTable</code> and then play with some LINQ on the resulting collection.</p>
<p>So we can replace our previous version of code with the below one which make use of LINQ</p>
<p><a href="http://www.techiesweb.net/wp-content/uploads/2012/08/linq-datatable.png"><img class="alignnone size-full wp-image-328" title="linq-datatable" src="http://www.techiesweb.net/wp-content/uploads/2012/08/linq-datatable.png" alt="" width="626" height="248" /></a></p>
<p>For more information visit the msdn page <a href="http://msdn.microsoft.com/en-us/library/system.data.datatableextensions.asenumerable(v=vs.100).aspx">http://msdn.microsoft.com/en-us/library/system.data.datatableextensions.asenumerable(v=vs.100).aspx</a>.</p>
<p>Hope this helps you some day <img src='http://www.techiesweb.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>&nbsp;</p>
<p>The post <a href="http://www.techiesweb.net/how-to-convert-datatable-to-collection-of-custom-class-object/">How to Convert DataTable to Collection of Custom Class object</a> appeared first on <a href="http://www.techiesweb.net">TechiesWeb</a>.</p><img src="http://feeds.feedburner.com/~r/techiesweb/~4/t74BuRYjOXw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techiesweb.net/how-to-convert-datatable-to-collection-of-custom-class-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.techiesweb.net/how-to-convert-datatable-to-collection-of-custom-class-object/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 1.862 seconds. --><!-- Cached page generated by WP-Super-Cache on 2013-06-07 04:53:39 -->
