Thursday, August 30, 2012

Dialog Popup with hyper link

Java script function for Dialog popup 

After click the link popup the data which is return form that link.

link
@Html.ActionLink("Name", "Action","Controller",new {//data need to pass as query string}, new {
// html attributes
class = "LinkClassName", dialog-title = "this is tiltle name ",  dialog-id  = "dailog id" ....
});

 $(".LinkClassName").live("click", function (e) {
            e.preventDefault();     
.append($loading) // this is for load image for fully loaded 
.addClass("dialog") // css class for loading 
.attr("id", $(this) // div id 
.attr("dialog-id")) // poup id
.attr("dialog-path", $(this).attr("data-dialog-path")) // after close page refresh 
.appendTo("body") // attached div content to the body 
.dialog({
   title: $(this).attr("data-dialog-title"), // popup dialog title 
   close: function () {  $(this).remove()   }, // close finction 
   modal: true, /
   resizable: false,
   width: '400px'
}).load(this.href); // href is the url
        });
more details available here.(http://jqueryui.com/)


Form submit using Ajax 


var form = $("#yourFormId");
$.ajax({
                url: '@Url.Action("ActionName","ControllerName")',
                data: form.serialize(),
                type: 'POST',
                success: function (data) {
                    $("#targetUpdateDiv").html(data);
                }
            });

Tuesday, June 26, 2012


ASP.net MVC3 Date Formats validation Issued (dd/mm/yyyy vs mm/dd/yyyy) 


Client side  passing date format as "dd/mm/yyyy" format. but model is return format is incorrect its cheeking mm/dd/yyyy. i have found that issue in mvc web application. 
solution

Reason is that web server culture info is used as "en-us" its validate format "mm/dd/yyyy".  then i found that we can change the culture dynamically in the following way .

Option 1: Page level

The Culture used by the individual Page can be set via the Culture property.
<%@ Page Culture="en-SG" Language="C#" %>

Option 2: Application wide (web.Config)

The Culture can be set Application wide by adding the  node to the web.Config file. The  node must be placed inside .
<system.web>
  <globalization culture="en-SG"/>

Option 3: Thread level

The Culture of the current Thread can be changed programatically be setting the System.Threading.Thread.CurrentThread.CurrentCulture property.
The following example demonstrates how to get the user-agent(browsers) preferred UserLanguage property on each Request and set the Threads CurrentCulture during the Application_BeginRequest Event.
protected void Application_BeginRequest(Object sender, EventArgs e)
{
    CultureInfo requestCulture;
    try
    {        
        requestCulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages[0]);
    }
    catch
    {
        // Return server Culture if none available in HttpHeaders.
        requestCulture = CultureInfo.CurrentCulture;
    }
    System.Threading.Thread.CurrentThread.CurrentCulture = requestCulture;
}