Skip to content


JQueryUI Datepicker in ASP.Net MVC

Technocrati code : M2U2PWSNTKW3

Datepicker is nice and cool plugin for displaying the calendar with ease. It is very easy to use JQuery plugin, it comes as part of JQueryUI library, so if you want to use this – first download JQueryUI from http://jqueryui.com/download and also download JQuery(http://docs.jquery.com/Downloading_jQuery) if you haven’t done yet.

image 

For e.g. if you have a form like one below

<% using(Html.BeginForm()){%>
  <fieldset>
    <legend>Event Information</legend>
     <p>
        <label for="EventName">Event Name:</label>
        <%= Html.TextBox("EventName")%>
            </p>
            <p>
            <label for="StartDate">Start Date:</label>
            <%= Html.TextBox("StartDate")%>
            </p>
            <p>
            <label for="EndDate">End Date:</label>
            <%= Html.TextBox("EndDate")%>
            </p>
            <p>
                <input type="submit" value="Save" />
            </p>
  </fieldset>
<% }%>

and you want to attach datepicker to “StartDate” and “EndDate” input fields,

Continued…

Posted in .NET, CodeProject, JQuery, JavaScript, MVC.

Tagged with , , , , .


Logging execution time using AOP

Download the source code for this tutorial from  – http://www.rajeeshcv.com/download/ProfilingSample.zip

What happens if your client complains that your application is running very slow!!! or in your load/stress testing you found that some functionalities are very slow in executing than expected. This is the time where you go for profiling the execution, to analyse the root cause of these issues.

So how we could develop a profiler, where we don’t have to wrap our normal code in a profiling code.

Before going to create the profiler, we have to decide where to put the profiled information. In this tutorial, I am making use of Log4Net as underlying layer to store this information. If you have not used Log4Net before, I suggest you to read http://www.beefycode.com/post/Log4Net-Tutorial-pt-1-Getting-Started.aspx as a starting point.

With the help of AOP (Aspect-Oriented Programming) we could do the profiling task without interrupting the actual code.

AOP is a programming paradigm in which secondary or supporting functions are isolated from the main program’s business logic

Source : Wikipedia

So in order bring the AOP functionality into this application, I am going to use a third party library PostSharp  which I believe this is one of the best that is available in the market. Please download it from http://www.sharpcrafters.com/postsharp/download.

So, now we have got the basic things to start with and now let’s start coding….

Start a new solution in visual studio and add a new console application project to it. Then add the below references to the newly created project

  1. Add reference to the Log4Net.dll
  2. Add reference to PostSharp.Laos.dll and PostSharp.Public.dll (Please read http://www.sharpcrafters.com/postsharp/documentation/getting-started to get the basic installation procedure)

Next, create a new attribute class called “ProfileMethodAttribute” – this class is responsible for doing the profiling work. Make sure that you have decorated this class with “Serializable” attribute

Continued…

Posted in .NET, ASP.NET, CodeProject, MVC.

Tagged with , , .


Check out Save Our Tigers | Join the Roar

Save Our Tigers | Join the Roar

Tiger-blog

Our national animal is fighting for its life. From around 40,000 at the turn of the last century, there are just 1411 tigers left in India.

If we don’t act now, we could lose this part of our heritage forever.
Speak up, blog, share the concern, stay informed… Every little bit helps.

Posted in General.


ASP.Net MVC – Conditional rendering Partial Views with Action<T> delegate

This is an update to my previous post regarding conditional rendering partial views, in that I used the internal implementation of the Html.RenderPartail(…) method to create the Html extension. Later I found a simple way to achieve the same using Action<T> delegate

<p>Partial rendering with Action Methods</p>
<% Html.PartialIf(this.Model.Exists, html => html.RenderPartial("MyPartialView")); %>

If you look at the “PartialIf” implementation, it is simple, cleaner than the previous technique I have mentioned in my post.

public static void PartialIf(this HtmlHelper htmlHelper, bool condition, Action<HtmlHelper> action)
{
    if (condition)
    {
        action.Invoke(htmlHelper);
    }
}

That’s it :)

Posted in .NET, ASP.NET, CodeProject, MVC.

Tagged with , , , .


ASP.Net MVC – Conditional rendering Partial Views


Update : Later I found a cleaner and simple approach to do the same – read this post ASP.Net MVC – Conditional rendering Partial Views with Action<T> delegate

Following my previous post about Conditional Rendering, one of my colleague asked me how to render the partial view based on a condition.

Normal way of doing this is

<p>Normal partial rendering based on condition</p>
<% if(this.Model.Exists)
 {
     Html.RenderPartial("MyPartialView");
 } %>

I am not sure about any other technique for rendering partial view conditionally other than this (correct me if I am wrong :) ).

Then I thought about copying the pattern I have used in my previous post and came up with this code which could conditionally render partial views and you could use the Html extension like below, which more clean than the previous

<% Html.PartialIf(this.Model.Exists, "MyPartialView"); %>

Continued…

Posted in .NET, ASP.NET, MVC.

Tagged with , .