<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Rajan's Blog - ASP.NET MVC</title>
    <link>http://blog.rajan.net.in/</link>
    <description>Experience Talks</description>
    <language>en-us</language>
    <copyright>Rajan R.G</copyright>
    <lastBuildDate>Sat, 13 Feb 2010 19:22:31 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>rgrajan@gmail.com</managingEditor>
    <webMaster>rgrajan@gmail.com</webMaster>
    <item>
      <trackback:ping>http://blog.rajan.net.in/Trackback.aspx?guid=3a795ab9-6785-4dd8-97d4-02e33bbd8153</trackback:ping>
      <pingback:server>http://blog.rajan.net.in/pingback.aspx</pingback:server>
      <pingback:target>http://blog.rajan.net.in/PermaLink,guid,3a795ab9-6785-4dd8-97d4-02e33bbd8153.aspx</pingback:target>
      <dc:creator>Rajan R.G</dc:creator>
      <wfw:comment>http://blog.rajan.net.in/CommentView,guid,3a795ab9-6785-4dd8-97d4-02e33bbd8153.aspx</wfw:comment>
      <wfw:commentRss>http://blog.rajan.net.in/SyndicationService.asmx/GetEntryCommentsRss?guid=3a795ab9-6785-4dd8-97d4-02e33bbd8153</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The important functionality of any ecommerce system is to transfer the content using
SSL when the user enters the user name &amp; password or while accepting the credit
card info. <a href="http://blog.stevensanderson.com/2008/08/05/adding-httpsssl-support-to-aspnet-mvc-routing/" target="_blank">Steve
Sanderson</a> has blogged about this and unfortunately it didn’t work for me. Also <a href="http://aspnet.codeplex.com/releases/view/24471" target="_blank">MVC
Futures</a> has RequiresSSL extension which transform the content to secure. But in
a typical system, we need to redirect back to HTTP as well, i.e if there is a booking
flow, after we get the credit card and validating the payment details, the confirmation
page might or should be in HTTP. 
</p>
        <p>
There are various solution available, i have decided to use the MVC Futures code and
slightly modify the same to implement this functionality. 
</p>
        <pre class="brush: csharp;">public sealed class SwitchSsl : FilterAttribute, IAuthorizationFilter
{
    public void OnAuthorization(AuthorizationContext filterContext)
    {
        if (!Enable)
            return;

        if (filterContext == null)
        {
            throw new ArgumentNullException("filterContext");
        }
        if (!filterContext.HttpContext.Request.IsSecureConnection &amp;&amp; Mode==Protocol.https)
        {
            if (!this.Redirect)
            {
                throw new HttpException(0x193, "Must use SSL");
            }
            RedirectUrl(Protocol.https, filterContext);
        }
        else if (filterContext.HttpContext.Request.IsSecureConnection &amp;&amp; Mode==Protocol.http)
        {
            RedirectUrl(Protocol.http, filterContext);
        }
    }

    public bool Redirect { get; set; }

    public Protocol Mode { get; set; }

    public bool Enable
    {
        get {
            return Convert.ToBoolean(ConfigurationManager.AppSettings.Get("EnableSsl"));
        }
    }

    private void RedirectUrl(Protocol scheme, AuthorizationContext filterContext)
    {
        UriBuilder builder2 = new UriBuilder();
        builder2.Scheme = scheme.ToString();
        builder2.Host = filterContext.HttpContext.Request.Url.Host;
        builder2.Path = filterContext.HttpContext.Request.RawUrl;
        UriBuilder builder = builder2;
        filterContext.Result = new RedirectResult(builder.ToString());
    }

    public enum Protocol
    {
        http,
        https
    }

}</pre>
        <p>
Enable property is an optional configuration in the web.config, so that we can enable
this only in the production environment. And in the controller action,we can call
like below.
</p>
        <pre class="brush: csharp;">[SwitchSsl(Redirect = true, Mode=SwitchSsl.Protocol.https)]
public ActionResult Reserve()</pre>
        <p>
Happy Coding!
</p>
        <img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=3a795ab9-6785-4dd8-97d4-02e33bbd8153" />
      </body>
      <title>ASP.NET MVC – Switch between secure(https or ssl) &amp; unsecure(http) connections</title>
      <guid isPermaLink="false">http://blog.rajan.net.in/PermaLink,guid,3a795ab9-6785-4dd8-97d4-02e33bbd8153.aspx</guid>
      <link>http://blog.rajan.net.in/2010/02/13/ASPNETMVCSwitchBetweenSecurehttpsOrSslUnsecurehttpConnections.aspx</link>
      <pubDate>Sat, 13 Feb 2010 19:22:31 GMT</pubDate>
      <description>&lt;p&gt;
The important functionality of any ecommerce system is to transfer the content using
SSL when the user enters the user name &amp;amp; password or while accepting the credit
card info. &lt;a href="http://blog.stevensanderson.com/2008/08/05/adding-httpsssl-support-to-aspnet-mvc-routing/" target="_blank"&gt;Steve
Sanderson&lt;/a&gt; has blogged about this and unfortunately it didn’t work for me. Also &lt;a href="http://aspnet.codeplex.com/releases/view/24471" target="_blank"&gt;MVC
Futures&lt;/a&gt; has RequiresSSL extension which transform the content to secure. But in
a typical system, we need to redirect back to HTTP as well, i.e if there is a booking
flow, after we get the credit card and validating the payment details, the confirmation
page might or should be in HTTP. 
&lt;/p&gt;
&lt;p&gt;
There are various solution available, i have decided to use the MVC Futures code and
slightly modify the same to implement this functionality. 
&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;public sealed class SwitchSsl : FilterAttribute, IAuthorizationFilter
{
    public void OnAuthorization(AuthorizationContext filterContext)
    {
        if (!Enable)
            return;

        if (filterContext == null)
        {
            throw new ArgumentNullException(&amp;quot;filterContext&amp;quot;);
        }
        if (!filterContext.HttpContext.Request.IsSecureConnection &amp;amp;&amp;amp; Mode==Protocol.https)
        {
            if (!this.Redirect)
            {
                throw new HttpException(0x193, &amp;quot;Must use SSL&amp;quot;);
            }
            RedirectUrl(Protocol.https, filterContext);
        }
        else if (filterContext.HttpContext.Request.IsSecureConnection &amp;amp;&amp;amp; Mode==Protocol.http)
        {
            RedirectUrl(Protocol.http, filterContext);
        }
    }

    public bool Redirect { get; set; }

    public Protocol Mode { get; set; }

    public bool Enable
    {
        get {
            return Convert.ToBoolean(ConfigurationManager.AppSettings.Get(&amp;quot;EnableSsl&amp;quot;));
        }
    }

    private void RedirectUrl(Protocol scheme, AuthorizationContext filterContext)
    {
        UriBuilder builder2 = new UriBuilder();
        builder2.Scheme = scheme.ToString();
        builder2.Host = filterContext.HttpContext.Request.Url.Host;
        builder2.Path = filterContext.HttpContext.Request.RawUrl;
        UriBuilder builder = builder2;
        filterContext.Result = new RedirectResult(builder.ToString());
    }

    public enum Protocol
    {
        http,
        https
    }

}&lt;/pre&gt;
&lt;p&gt;
Enable property is an optional configuration in the web.config, so that we can enable
this only in the production environment. And in the controller action,we can call
like below.
&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;[SwitchSsl(Redirect = true, Mode=SwitchSsl.Protocol.https)]
public ActionResult Reserve()&lt;/pre&gt;
&lt;p&gt;
Happy Coding!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=3a795ab9-6785-4dd8-97d4-02e33bbd8153" /&gt;</description>
      <comments>http://blog.rajan.net.in/CommentView,guid,3a795ab9-6785-4dd8-97d4-02e33bbd8153.aspx</comments>
      <category>ASP.NET MVC</category>
    </item>
    <item>
      <trackback:ping>http://blog.rajan.net.in/Trackback.aspx?guid=26fc6121-f28c-487a-95e6-c36d290c628e</trackback:ping>
      <pingback:server>http://blog.rajan.net.in/pingback.aspx</pingback:server>
      <pingback:target>http://blog.rajan.net.in/PermaLink,guid,26fc6121-f28c-487a-95e6-c36d290c628e.aspx</pingback:target>
      <dc:creator>Rajan R.G</dc:creator>
      <wfw:comment>http://blog.rajan.net.in/CommentView,guid,26fc6121-f28c-487a-95e6-c36d290c628e.aspx</wfw:comment>
      <wfw:commentRss>http://blog.rajan.net.in/SyndicationService.asmx/GetEntryCommentsRss?guid=26fc6121-f28c-487a-95e6-c36d290c628e</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
It is important to have logging enabled in any production site which will be used
by the technical team to debug the issues or monitor the health of the site. We chose <a href="http://dotnetlog.theobjectguy.com/" target="_blank">BitFactory</a> logging
(Now the author is calling as Termite) to implement the logging in WCF Services, Business
Layer &amp; ASP.NET MVC Sites. 
</p>
        <p>
Why did we choose BitFactory?
</p>
        <ul>
          <li>
It is very easy to implement. 
</li>
          <li>
Absolutely working with complex categories (we have 43 projects in a solution with
more than 25 categories configured for logging) 
</li>
          <li>
No issue with Multithreading or Filelocking issue. 
</li>
        </ul>
        <p>
I have used Nlog, Log4net, MS Enterprise library &amp; Elmah in various projects,
somehow my choice at this time is BitFactory. Other frameworks are good on their own
flavor and i am not against any frameworks whether it is commercial or open source.
</p>
        <p>
In ASP.NET MVC we have to use HandleError attribute to redirect to the customized
error page and i would like to implement the logging using the same attribute. Thanks
to <a href="http://blog.ploeh.dk/2009/12/07/LoggingExceptionFilter.aspx" target="_blank">Mark
Seemann</a> for the poor man’s Dependency Injection for the logging. I used the same
snippet but tried to integrate BitFactory logging. 
</p>
        <p>
ErrorHandlingActionInvoker.cs
</p>
        <pre class="brush: csharp;">public class ErrorHandlingActionInvoker : ControllerActionInvoker
{
    private readonly IExceptionFilter filter;

    public ErrorHandlingActionInvoker(IExceptionFilter filter)
    {
        if (filter == null)
        {
            throw new ArgumentNullException("filter");
        }
        
        this.filter = filter;
    }

    protected override FilterInfo GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
    {
        var filterInfo =base.GetFilters(controllerContext, actionDescriptor);
        filterInfo.ExceptionFilters.Add(this.filter);
        return filterInfo;
    }

}</pre>
        <p>
ErrorHandlingControllerFactory.cs
</p>
        <pre class="brush: csharp;">public class ErrorHandlingControllerFactory : DefaultControllerFactory
{
    public override IController CreateController(RequestContext requestContext,string controllerName)
    {
        var controller =base.CreateController(requestContext,controllerName);
        var c = controller as Controller;
        if (c != null)
        {
            c.ActionInvoker = new ErrorHandlingActionInvoker(new LoggingExceptionFilter(new HandleErrorAttribute()));
        }
        return controller;
    }

}</pre>
        <p>
LoggingExceptionFilter.cs
</p>
        <pre class="brush: csharp;">public class LoggingExceptionFilter : IExceptionFilter
{
    private readonly IExceptionFilter filter;
    private readonly ConfigLogger logWriter = ConfigLogger.Instance;

    public LoggingExceptionFilter(IExceptionFilter filter) 
    { 
        if (filter == null) 
        { 
            throw new ArgumentNullException("filter"); 
        } 
        if (logWriter == null) 
        { 
            throw new ArgumentNullException("logWriter"); 
        } 
        this.filter = filter; 
    }

    public void OnException(ExceptionContext filterContext)
    {
        this.logWriter.LogError(filterContext.Exception);
        this.filter.OnException(filterContext);
    }
}</pre>
        <p>
Web.Config
</p>
        <pre class="brush: xml;">&lt;BitFactory.Logging name="global" xmlns="http://BitFactory.Logging"&gt;
  &lt;rollingDateFileLoggers&gt;
    &lt;rollingDateFileLogger isEnabled="true" name="FrontEndLogger" formattedFileName="C:\Logs\services_{timestamp:yyyyMMdd}.log"/&gt;
  &lt;/rollingDateFileLoggers&gt;
&lt;/BitFactory.Logging&gt;</pre>
        <p>
Add this line in Global.asax.cs
</p>
        <pre class="brush: csharp;">ControllerBuilder.Current.SetControllerFactory(new ErrorHandlingControllerFactory());</pre>
        <p>
Happy Coding!
</p>
        <img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=26fc6121-f28c-487a-95e6-c36d290c628e" />
      </body>
      <title>Using BitFactory logging in ASP.NET MVC HandleError</title>
      <guid isPermaLink="false">http://blog.rajan.net.in/PermaLink,guid,26fc6121-f28c-487a-95e6-c36d290c628e.aspx</guid>
      <link>http://blog.rajan.net.in/2009/12/20/UsingBitFactoryLoggingInASPNETMVCHandleError.aspx</link>
      <pubDate>Sun, 20 Dec 2009 17:16:53 GMT</pubDate>
      <description>&lt;p&gt;
It is important to have logging enabled in any production site which will be used
by the technical team to debug the issues or monitor the health of the site. We chose &lt;a href="http://dotnetlog.theobjectguy.com/" target="_blank"&gt;BitFactory&lt;/a&gt; logging
(Now the author is calling as Termite) to implement the logging in WCF Services, Business
Layer &amp;amp; ASP.NET MVC Sites. 
&lt;/p&gt;
&lt;p&gt;
Why did we choose BitFactory?
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
It is very easy to implement. 
&lt;/li&gt;
&lt;li&gt;
Absolutely working with complex categories (we have 43 projects in a solution with
more than 25 categories configured for logging) 
&lt;/li&gt;
&lt;li&gt;
No issue with Multithreading or Filelocking issue. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
I have used Nlog, Log4net, MS Enterprise library &amp;amp; Elmah in various projects,
somehow my choice at this time is BitFactory. Other frameworks are good on their own
flavor and i am not against any frameworks whether it is commercial or open source.
&lt;/p&gt;
&lt;p&gt;
In ASP.NET MVC we have to use HandleError attribute to redirect to the customized
error page and i would like to implement the logging using the same attribute. Thanks
to &lt;a href="http://blog.ploeh.dk/2009/12/07/LoggingExceptionFilter.aspx" target="_blank"&gt;Mark
Seemann&lt;/a&gt; for the poor man’s Dependency Injection for the logging. I used the same
snippet but tried to integrate BitFactory logging. 
&lt;/p&gt;
&lt;p&gt;
ErrorHandlingActionInvoker.cs
&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;public class ErrorHandlingActionInvoker : ControllerActionInvoker
{
    private readonly IExceptionFilter filter;

    public ErrorHandlingActionInvoker(IExceptionFilter filter)
    {
        if (filter == null)
        {
            throw new ArgumentNullException(&amp;quot;filter&amp;quot;);
        }
        
        this.filter = filter;
    }

    protected override FilterInfo GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
    {
        var filterInfo =base.GetFilters(controllerContext, actionDescriptor);
        filterInfo.ExceptionFilters.Add(this.filter);
        return filterInfo;
    }

}&lt;/pre&gt;
&lt;p&gt;
ErrorHandlingControllerFactory.cs
&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;public class ErrorHandlingControllerFactory : DefaultControllerFactory
{
    public override IController CreateController(RequestContext requestContext,string controllerName)
    {
        var controller =base.CreateController(requestContext,controllerName);
        var c = controller as Controller;
        if (c != null)
        {
            c.ActionInvoker = new ErrorHandlingActionInvoker(new LoggingExceptionFilter(new HandleErrorAttribute()));
        }
        return controller;
    }

}&lt;/pre&gt;
&lt;p&gt;
LoggingExceptionFilter.cs
&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;public class LoggingExceptionFilter : IExceptionFilter
{
    private readonly IExceptionFilter filter;
    private readonly ConfigLogger logWriter = ConfigLogger.Instance;

    public LoggingExceptionFilter(IExceptionFilter filter) 
    { 
        if (filter == null) 
        { 
            throw new ArgumentNullException(&amp;quot;filter&amp;quot;); 
        } 
        if (logWriter == null) 
        { 
            throw new ArgumentNullException(&amp;quot;logWriter&amp;quot;); 
        } 
        this.filter = filter; 
    }

    public void OnException(ExceptionContext filterContext)
    {
        this.logWriter.LogError(filterContext.Exception);
        this.filter.OnException(filterContext);
    }
}&lt;/pre&gt;
&lt;p&gt;
Web.Config
&lt;/p&gt;
&lt;pre class="brush: xml;"&gt;&amp;lt;BitFactory.Logging name=&amp;quot;global&amp;quot; xmlns=&amp;quot;http://BitFactory.Logging&amp;quot;&amp;gt;
  &amp;lt;rollingDateFileLoggers&amp;gt;
    &amp;lt;rollingDateFileLogger isEnabled=&amp;quot;true&amp;quot; name=&amp;quot;FrontEndLogger&amp;quot; formattedFileName=&amp;quot;C:\Logs\services_{timestamp:yyyyMMdd}.log&amp;quot;/&amp;gt;
  &amp;lt;/rollingDateFileLoggers&amp;gt;
&amp;lt;/BitFactory.Logging&amp;gt;&lt;/pre&gt;
&lt;p&gt;
Add this line in Global.asax.cs
&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;ControllerBuilder.Current.SetControllerFactory(new ErrorHandlingControllerFactory());&lt;/pre&gt;
&lt;p&gt;
Happy Coding!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=26fc6121-f28c-487a-95e6-c36d290c628e" /&gt;</description>
      <comments>http://blog.rajan.net.in/CommentView,guid,26fc6121-f28c-487a-95e6-c36d290c628e.aspx</comments>
      <category>ASP.NET MVC</category>
    </item>
    <item>
      <trackback:ping>http://blog.rajan.net.in/Trackback.aspx?guid=efa59e37-6e16-4834-972d-9d4c8d003792</trackback:ping>
      <pingback:server>http://blog.rajan.net.in/pingback.aspx</pingback:server>
      <pingback:target>http://blog.rajan.net.in/PermaLink,guid,efa59e37-6e16-4834-972d-9d4c8d003792.aspx</pingback:target>
      <dc:creator>Rajan R.G</dc:creator>
      <wfw:comment>http://blog.rajan.net.in/CommentView,guid,efa59e37-6e16-4834-972d-9d4c8d003792.aspx</wfw:comment>
      <wfw:commentRss>http://blog.rajan.net.in/SyndicationService.asmx/GetEntryCommentsRss?guid=efa59e37-6e16-4834-972d-9d4c8d003792</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In my current project I need to load the user control dynamically without post back.
After some googling found couple of posts which converts the partial view as string.
The issue here is it doesn’t support viewcontext, in my case i have custom view engine
which implements localization. Earlier i have gone through this useful <a href="http://elijahmanor.com/webdevdotnet/post/ASPNET-MVC-Cheat-Sheets.aspx" target="_blank">cheat
sheet</a>. Below is the simple implementation which works with custom view engine
and view context.
</p>
        <pre class="brush: csharp;">[AcceptVerbs(HttpVerbs.Get)]
public ActionResult LoadTopDestinations()
{
    return PartialView("TopDestinations");
}</pre>
        <p>
And this is how i call the controller from the javascript using jquery post.
</p>
        <pre class="brush: js;">function TopDestinationClick() {
    proxy.invoke("/Home/LoadTopDestinations", "", TopDestinationCallback, OnError);

}</pre>
        <p>
Thanks to Rick Strahl for the easy service proxy for jquery post.
</p>
        <pre class="brush: js;">function serviceProxy(serviceUrl)
{
    var _I = this;
    this.serviceUrl = serviceUrl;
    
    // *** Call a wrapped object
    this.invoke = function(method, data, callback, error) {
        // *** The service endpoint URL        
        var url = _I.serviceUrl + method;
        //alert(url);
        $.ajax({
            url: url,
            data: '',
            type: "GET",
            contentType: "html",
            timeout: 10000,
            success: callback,
            error: OnError
        });
    }
}

// *** Create a static instance
var serviceUrl = "";
var proxy = new serviceProxy(serviceUrl);</pre>
        <p>
And the callback event, just use jquery.html() method to load the partial view result.
</p>
        <img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=efa59e37-6e16-4834-972d-9d4c8d003792" />
      </body>
      <title>How to load partial view dynamically in ASP.NET MVC using JQuery</title>
      <guid isPermaLink="false">http://blog.rajan.net.in/PermaLink,guid,efa59e37-6e16-4834-972d-9d4c8d003792.aspx</guid>
      <link>http://blog.rajan.net.in/2009/11/21/HowToLoadPartialViewDynamicallyInASPNETMVCUsingJQuery.aspx</link>
      <pubDate>Sat, 21 Nov 2009 21:38:45 GMT</pubDate>
      <description>&lt;p&gt;
In my current project I need to load the user control dynamically without post back.
After some googling found couple of posts which converts the partial view as string.
The issue here is it doesn’t support viewcontext, in my case i have custom view engine
which implements localization. Earlier i have gone through this useful &lt;a href="http://elijahmanor.com/webdevdotnet/post/ASPNET-MVC-Cheat-Sheets.aspx" target="_blank"&gt;cheat
sheet&lt;/a&gt;. Below is the simple implementation which works with custom view engine
and view context.
&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;[AcceptVerbs(HttpVerbs.Get)]
public ActionResult LoadTopDestinations()
{
    return PartialView(&amp;quot;TopDestinations&amp;quot;);
}&lt;/pre&gt;
&lt;p&gt;
And this is how i call the controller from the javascript using jquery post.
&lt;/p&gt;
&lt;pre class="brush: js;"&gt;function TopDestinationClick() {
    proxy.invoke(&amp;quot;/Home/LoadTopDestinations&amp;quot;, &amp;quot;&amp;quot;, TopDestinationCallback, OnError);

}&lt;/pre&gt;
&lt;p&gt;
Thanks to Rick Strahl for the easy service proxy for jquery post.
&lt;/p&gt;
&lt;pre class="brush: js;"&gt;function serviceProxy(serviceUrl)
{
    var _I = this;
    this.serviceUrl = serviceUrl;
    
    // *** Call a wrapped object
    this.invoke = function(method, data, callback, error) {
        // *** The service endpoint URL        
        var url = _I.serviceUrl + method;
        //alert(url);
        $.ajax({
            url: url,
            data: '',
            type: &amp;quot;GET&amp;quot;,
            contentType: &amp;quot;html&amp;quot;,
            timeout: 10000,
            success: callback,
            error: OnError
        });
    }
}

// *** Create a static instance
var serviceUrl = &amp;quot;&amp;quot;;
var proxy = new serviceProxy(serviceUrl);&lt;/pre&gt;
&lt;p&gt;
And the callback event, just use jquery.html() method to load the partial view result.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=efa59e37-6e16-4834-972d-9d4c8d003792" /&gt;</description>
      <comments>http://blog.rajan.net.in/CommentView,guid,efa59e37-6e16-4834-972d-9d4c8d003792.aspx</comments>
      <category>ASP.NET MVC</category>
    </item>
    <item>
      <trackback:ping>http://blog.rajan.net.in/Trackback.aspx?guid=06b3a7f2-079e-411a-99f4-0c06012b3f1d</trackback:ping>
      <pingback:server>http://blog.rajan.net.in/pingback.aspx</pingback:server>
      <pingback:target>http://blog.rajan.net.in/PermaLink,guid,06b3a7f2-079e-411a-99f4-0c06012b3f1d.aspx</pingback:target>
      <dc:creator>Rajan R.G</dc:creator>
      <wfw:comment>http://blog.rajan.net.in/CommentView,guid,06b3a7f2-079e-411a-99f4-0c06012b3f1d.aspx</wfw:comment>
      <wfw:commentRss>http://blog.rajan.net.in/SyndicationService.asmx/GetEntryCommentsRss?guid=06b3a7f2-079e-411a-99f4-0c06012b3f1d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We used to bind model class in ASP.NET MVC dropdownlist like below
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:08f84aed-8b0a-42a0-91f0-8a85e079aee4" class="wlWriterEditableSmartContent">
          <pre name="code" class="xml">&lt;%= Html.DropDownList("ApprovalStatus", Model.ApprovalStatus, new { @class = "select", onchange = "javascript:CheckApprovalStatus(this);" })%&gt;</pre>
        </div>
        <p>
The HTML output of the above is
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:9f2d86d5-ff23-41e0-b9d0-d413521a650f" class="wlWriterEditableSmartContent">
          <pre name="code" class="xml">&lt;select class="select" id="ApprovalStatus" name="ApprovalStatus" &gt;
&lt;option value="Approved"&gt;Approved&lt;/option&gt;
&lt;option value="Rejected"&gt;Rejected&lt;/option&gt;
&lt;option value="InProgress"&gt;In Progress&lt;/option&gt;
&lt;/select&gt;
</pre>
        </div>
        <p>
What if you would like to have Keys &amp; Value separately and like below and if the
model class is KeyValuePair
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:66df720f-2d17-4f72-904c-e3371e6facb8" class="wlWriterEditableSmartContent">
          <pre name="code" class="xml">&lt;select class="select" id="Country" name="Country"&gt;
&lt;option value="US"&gt;United States&lt;/option&gt;
&lt;option value="IN"&gt;India&lt;/option&gt;
&lt;option value="SG"&gt;Singapore&lt;/option&gt;
&lt;/select&gt;</pre>
        </div>
        <p>
then it should bind with Keys &amp; Values.
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:ef896479-82af-4d2a-aab0-69a9a667a56e" class="wlWriterEditableSmartContent">
          <pre name="code" class="c#">CountryList = new SelectList(Country.ToList(),"Key","Value");</pre>
        </div>
        <p>
Happy Coding!
</p>
        <img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=06b3a7f2-079e-411a-99f4-0c06012b3f1d" />
      </body>
      <title>Bind KeyValuePair class to ASP.NET MVC HTML DropDownList</title>
      <guid isPermaLink="false">http://blog.rajan.net.in/PermaLink,guid,06b3a7f2-079e-411a-99f4-0c06012b3f1d.aspx</guid>
      <link>http://blog.rajan.net.in/2009/07/26/BindKeyValuePairClassToASPNETMVCHTMLDropDownList.aspx</link>
      <pubDate>Sun, 26 Jul 2009 05:30:00 GMT</pubDate>
      <description>&lt;p&gt;
We used to bind model class in ASP.NET MVC dropdownlist like below
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:08f84aed-8b0a-42a0-91f0-8a85e079aee4" class="wlWriterEditableSmartContent"&gt;&lt;pre name="code" class="xml"&gt;&amp;lt;%= Html.DropDownList("ApprovalStatus", Model.ApprovalStatus, new { @class = "select", onchange = "javascript:CheckApprovalStatus(this);" })%&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
The HTML output of the above is
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:9f2d86d5-ff23-41e0-b9d0-d413521a650f" class="wlWriterEditableSmartContent"&gt;&lt;pre name="code" class="xml"&gt;&amp;lt;select class="select" id="ApprovalStatus" name="ApprovalStatus" &amp;gt;
&amp;lt;option value="Approved"&amp;gt;Approved&amp;lt;/option&amp;gt;
&amp;lt;option value="Rejected"&amp;gt;Rejected&amp;lt;/option&amp;gt;
&amp;lt;option value="InProgress"&amp;gt;In Progress&amp;lt;/option&amp;gt;
&amp;lt;/select&amp;gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
What if you would like to have Keys &amp;amp; Value separately and like below and if the
model class is KeyValuePair
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:66df720f-2d17-4f72-904c-e3371e6facb8" class="wlWriterEditableSmartContent"&gt;&lt;pre name="code" class="xml"&gt;&amp;lt;select class="select" id="Country" name="Country"&amp;gt;
&amp;lt;option value="US"&amp;gt;United States&amp;lt;/option&amp;gt;
&amp;lt;option value="IN"&amp;gt;India&amp;lt;/option&amp;gt;
&amp;lt;option value="SG"&amp;gt;Singapore&amp;lt;/option&amp;gt;
&amp;lt;/select&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
then it should bind with Keys &amp;amp; Values.
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:ef896479-82af-4d2a-aab0-69a9a667a56e" class="wlWriterEditableSmartContent"&gt;&lt;pre name="code" class="c#"&gt;CountryList = new SelectList(Country.ToList(),"Key","Value");&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
Happy Coding!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.rajan.net.in/aggbug.ashx?id=06b3a7f2-079e-411a-99f4-0c06012b3f1d" /&gt;</description>
      <comments>http://blog.rajan.net.in/CommentView,guid,06b3a7f2-079e-411a-99f4-0c06012b3f1d.aspx</comments>
      <category>ASP.NET MVC</category>
    </item>
  </channel>
</rss>