Tuesday, October 22, 2013

MVC Dropdown Binding in the View



DropDownListFor:

@Html.DropDownListFor(model => model.RoleID, new SelectList(ViewBag.Role as System.Collections.IEnumerable, "id", "roleName"), "Select", new { id = "ddlRoles", @class = "ft-sb validate[required]" })


DropDownList:

var listBranch = new List<SelectListItem>();
listBranch.Add(new SelectListItem { Text = "--Select--", Value = string.Empty });

     foreach (var agents in ViewBag.BranchList)
            {
                listBranch.Add(new SelectListItem { Text = agents, Value = agents });
            }

@Html.DropDownList("ddlBranchTypeValues", listBranch, new { @class = "ft-tb", @id = "ddlBranchTypeValues" })

Jquery Ajax Call With & Without Json



Jquery Ajax Call

var str = $('#loginform').serialize();
$.ajax({
type: 'POST',
url: "../Sessions/AttemptSenderLogin?txtEmail=" + $("#txtEmail").val() + "&txtPassword=" + $("#txtPassword").val(),
data: str,
success: function(data) {
},
error: function(res) {
}
});

Jquery Ajax Call  With JsonType

$.ajax({
type: "GET",
url: "/AdminTransactions/GetThreatMetrixDeviceIdDetails",
data: "deviceId=" + $('#HdnDeviceId').val() + "&transId=" + $('#HdnTransaciontId').val(),
dataType: 'json',
error: function () {
},
success: function (data) {
if (data != '') {
$.each(data, function (index, item) {
//item.ProcessingFee // Get Json Values
});
}
}
});

Skip Non Business Days when Adding Days in Datetime in C#

public static DateTime AddWorkdays(DateTime originalDate, int workDays, bool transtype, bool daysSkip)
        {
            DateTime tmpDate = originalDate;
            if (transtype && !daysSkip) // Check Days Condition Checking for Saturdays and Sundays
            {
                while (workDays > 0)
                {
                    tmpDate = tmpDate.AddDays(1);
                    if (tmpDate.DayOfWeek < DayOfWeek.Saturday &&
                        tmpDate.DayOfWeek > DayOfWeek.Sunday)
                        workDays--;
                }
            }
            if (!transtype && daysSkip) // Card Days Condition Checking for only Sundays
            {
                while (workDays > 0)
                {
                    tmpDate = tmpDate.AddDays(1);
                    if (tmpDate.DayOfWeek > DayOfWeek.Sunday)
                        workDays--;
                }
            }
            if (!transtype && !daysSkip) // Card
            {
                tmpDate = AddWorkdays(tmpDate, workDays, false, true);
            }
            return tmpDate;
        }