Thursday 20 December 2012

Improvements in C# 4.0



1. Dynamic Lookup

There is a new static type named dynamic. We can use it as object of any type. If there is any error on its usage, we would get it on runtime only. For example:
dynamic integerValue = 1; 
dynamic stringValue = " a string"; 
dynamic Result = integerValue + stringValue;
Output of this would be: 1 a string.
But, if you change the last line to:
dynamic Result = integerValue & stringValue;
You will not get any compilation error, but the following error on runtime:
Operator '&' cannot be applied to operands of type 'int' and 'string'

2. Named Parameters

Named parameters allow you to ignore the parameter order and mention parameters with names in a different order. For example:

public void FunctionNamedParam(int x, int y , int z)
On function call, it would be:
FunctionNamedParam(x:1, z:3, y:2);
Although we are sending a value for the parameter z before its order in the function declaration, but these would be equal to x=1, y=2, z=3.

Monday 3 December 2012

Model Pop Up in MVC3


Model Pop Using Jquery UI

<!-- Model PopUp Content-->
<script type="text/javascript">
    var linkObj;
    $(function () {
        $(".authorize").button();

        $('#updateDialog').dialog({
            autoOpen: false,
            width: 950,
            resizable: false,
            modal: true,
            buttons: {
                "Post": function () {
                    $("#update-message").html(''); //make sure there is nothing on the message before we continue                        
                    $("#updateForm").submit();
                },
                "Unpost": function () {
                    var TransId = document.getElementById("hdnTransId").value;
                    var TransType = document.getElementById("hdnTransType").value;
                    if (parseInt(TransId) != 0 && parseInt(TransType) != 0) {
                        $(document).ready(function () {
                            $("#ajax_loading_div").addClass("loading");
                            $.ajax({
                                cache: false,
                                async: true,
                                type: "GET",
                                dataType: "json",
                                url: "../Services/FinTranService.svc/UnpostAuth",
                                data: { Id: TransId, Type: TransType },

                                contentType: "application/json;charset=utf-8",
                                success: function (r) {
                                    if (r != null) {
                                        $("#ajax_loading_div").removeClass("loading");
                                        $(this).dialog("close");
                                    }
                                },
                                error: function (e) {
                                    $("#ajax_loading_div").removeClass("loading");
                                    $(this).dialog("close");
                                }
                            });
                        });
                    }
                }
            }
        });
   
    $(".authorize").click(function () {
        //change the title of the dialgo
        linkObj = $(this);
        var dialogDiv = $('#updateDialog');
        var viewUrl = linkObj.attr('href');
        $.get(viewUrl, function (data) {
            dialogDiv.html(data);
            dialogDiv.dialog('open');
        });
        return false;
    });
});


In List
@Html.ActionLink("Authorize", "ViewAuthorize", new { TAid = item.TransId,mode=item.TransType}, new { @class = "authorize" })       


Pop up content page as partial view
@using (Ajax.BeginForm("ViewTransAuthorize", "FinanceTransaction", null,
        new AjaxOptions
        {
            UpdateTargetId = "update-message",
            InsertionMode = InsertionMode.Replace,
            HttpMethod = "POST",
            OnSuccess = "updateSuccess"
        }, new { @id = "updateForm" }))

    <div id="update-message" class="error invisible">
    </div>

//Your Content here

}