<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Fransiscus Setiawan &#187; ASP.NET</title>
	<atom:link href="http://fransiscuss.com/category/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://fransiscuss.com</link>
	<description>My notepad of knowledge and my passion in development</description>
	<lastBuildDate>Tue, 22 May 2012 05:59:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='fransiscuss.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Fransiscus Setiawan &#187; ASP.NET</title>
		<link>http://fransiscuss.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://fransiscuss.com/osd.xml" title="Fransiscus Setiawan" />
	<atom:link rel='hub' href='http://fransiscuss.com/?pushpress=hub'/>
		<item>
		<title>ModelState Errors in MVC through JSON</title>
		<link>http://fransiscuss.com/2012/05/15/modelstate-errors-in-mvc-through-json/</link>
		<comments>http://fransiscuss.com/2012/05/15/modelstate-errors-in-mvc-through-json/#comments</comments>
		<pubDate>Tue, 15 May 2012 13:06:50 +0000</pubDate>
		<dc:creator>fransiscuss</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>

		<guid isPermaLink="false">http://fransiscuss.com/?p=360</guid>
		<description><![CDATA[Normally, when you used HttpPost/Form submission to post the view through the controller then you can have the model validation applied automatically through @Html.ValidationSummary() But how do you get the ModelState errors through Json? You can still use LINQ to get the model errors from the ModelState and pass it through JSON Code Snippet public [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fransiscuss.com&#038;blog=26182965&#038;post=360&#038;subd=fransiscuss&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Normally, when you used HttpPost/Form submission to post the view through the controller then you can have the model validation applied automatically through @Html.ValidationSummary()</p>
<p>But how do you get the ModelState errors through Json? You can still use LINQ to get the model errors from the ModelState and pass it through JSON</p>
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;">Code Snippet</div>
<div style="background:#ddd;max-height:300px;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 3em;padding:0 0 0 5px;" start="122">
<li><span style="color:#0000ff;">public</span> <span style="color:#2b91af;">ActionResult</span> JsonRegister(<span style="color:#2b91af;">MemberModel</span>.<span style="color:#2b91af;">RegistrationModel</span> model)</li>
<li style="background:#f3f3f3;">        {</li>
<li>            <span style="color:#0000ff;">string</span> error = <span style="color:#0000ff;">string</span>.Empty;</li>
<li style="background:#f3f3f3;"></li>
<li>            <span style="color:#0000ff;">if</span> (!ModelState.IsValid)</li>
<li style="background:#f3f3f3;">            {</li>
<li>                <span style="color:#2b91af;">IEnumerable</span>&lt;System.Web.Mvc.<span style="color:#2b91af;">ModelError</span>&gt; modelerrors = ModelState.SelectMany(x =&gt; x.Value.Errors);</li>
<li style="background:#f3f3f3;">                <span style="color:#0000ff;">foreach</span> (<span style="color:#0000ff;">var</span> modelerror <span style="color:#0000ff;">in</span> modelerrors)</li>
<li>                {</li>
<li style="background:#f3f3f3;">                    error += modelerror.ErrorMessage + <span style="color:#a31515;">&#8220;\n&#8221;</span>;</li>
<li>                }</li>
<li style="background:#f3f3f3;">            }</li>
<li>            <span style="color:#0000ff;">return</span> Json(<span style="color:#0000ff;">new</span> { success = <span style="color:#0000ff;">false</span>, errors = error }, <span style="color:#2b91af;">JsonRequestBehavior</span>.AllowGet);</li>
<li style="background:#f3f3f3;">        }</li>
</ol>
</div>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/fransiscuss.wordpress.com/360/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/fransiscuss.wordpress.com/360/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/fransiscuss.wordpress.com/360/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/fransiscuss.wordpress.com/360/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/fransiscuss.wordpress.com/360/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/fransiscuss.wordpress.com/360/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/fransiscuss.wordpress.com/360/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/fransiscuss.wordpress.com/360/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/fransiscuss.wordpress.com/360/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/fransiscuss.wordpress.com/360/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/fransiscuss.wordpress.com/360/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/fransiscuss.wordpress.com/360/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/fransiscuss.wordpress.com/360/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/fransiscuss.wordpress.com/360/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fransiscuss.com&#038;blog=26182965&#038;post=360&#038;subd=fransiscuss&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://fransiscuss.com/2012/05/15/modelstate-errors-in-mvc-through-json/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/70e5c1d49eb30cdc979601f6e85e962a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">fransiscuss</media:title>
		</media:content>
	</item>
	</channel>
</rss>
