1) Jquery Simple Alert Function with Yes or No type.
function JQConfirm(Msg) {
var NewDialog = $('
NewDialog.dialog({
autoOpen: true,
width: 500,
modal: true,
resizable: false,
draggable: false,
position: 'center',
closeOnEscape: true,
title: "JQuery Alerts",
buttons: {
Yes: function () {
$(this).dialog('close');
},
No: function () {
$(this).dialog('close');
}
}
});
}
2) OnFocus sample
$(document).ready(function () {
$('#TextFieldName').focus();
});
3) Get the value from TextBox
$("#TextBoxField").val();
3)Button Click Event
function ButtonClick(varButtonText) {
var varUrl = "";
if (varButtonText == "Yes") {
varUrl = "/ControllerName/ViewName?QueryStringName=" + SendingValue;
}
else if (varButtonText == "No") {
varUrl = "/ControllerName/ViewName?QueryStringName=" + SendingValue;
}
document.forms[0].action = "<%=SolutionName.Controllers.Utils.getURL() %>" + varUrl;
document.forms[0].submit();
}
GetUrl()
public static string getAppBaseURL()
{
string strURL = string.Empty;
string Currenturl = HttpContext.Current.Request.Url.AbsoluteUri;
string strRawUrl = HttpContext.Current.Request.RawUrl;
string strApplicationPath = HttpContext.Current.Request.ApplicationPath;
strURL = ((Currenturl.IndexOf("http://")>0) && (strRawUrl.IndexOf("http://")<=0))?Currenturl.Substring(0, Currenturl.Replace("http://","").IndexOf(strRawUrl)+7):Currenturl.Substring(0, Currenturl.IndexOf(strRawUrl));
if (strApplicationPath != @"/")
{
strURL += HttpContext.Current.Request.ApplicationPath;
}
return strURL;
}
How to Call Json from script to Controller.
function AlreadyExists(varName) {
var dataToSend =
{
Parameter: varName
};
$.ajax({
url: "@UrlPath/Controller/ActionName",
type: "GET",
data: dataToSend,
cache: false,
success: function (data) {
getResult set from data.
}
}
// Controller.
public JsonResultActionName(string Parameter)
{
List li = new List();
li.Add("2");
li.Add("1");
li.Add("3");
return Json(li, JsonRequestBehavior.AllowGet);
}
2) How to Create Partial view and How to load over the Json.
Loading View :
==================================================
function JQConfirm(Msg) {
var NewDialog = $('
' + Msg + '
');NewDialog.dialog({
autoOpen: true,
width: 500,
modal: true,
resizable: false,
draggable: false,
position: 'center',
closeOnEscape: true,
title: "JQuery Alerts",
buttons: {
Yes: function () {
$(this).dialog('close');
},
No: function () {
$(this).dialog('close');
}
}
});
}
2) OnFocus sample
$(document).ready(function () {
$('#TextFieldName').focus();
});
3) Get the value from TextBox
$("#TextBoxField").val();
3)Button Click Event
function ButtonClick(varButtonText) {
var varUrl = "";
if (varButtonText == "Yes") {
varUrl = "/ControllerName/ViewName?QueryStringName=" + SendingValue;
}
else if (varButtonText == "No") {
varUrl = "/ControllerName/ViewName?QueryStringName=" + SendingValue;
}
document.forms[0].action = "<%=SolutionName.Controllers.Utils.getURL() %>" + varUrl;
document.forms[0].submit();
}
GetUrl()
public static string getAppBaseURL()
{
string strURL = string.Empty;
string Currenturl = HttpContext.Current.Request.Url.AbsoluteUri;
string strRawUrl = HttpContext.Current.Request.RawUrl;
string strApplicationPath = HttpContext.Current.Request.ApplicationPath;
strURL = ((Currenturl.IndexOf("http://")>0) && (strRawUrl.IndexOf("http://")<=0))?Currenturl.Substring(0, Currenturl.Replace("http://","").IndexOf(strRawUrl)+7):Currenturl.Substring(0, Currenturl.IndexOf(strRawUrl));
if (strApplicationPath != @"/")
{
strURL += HttpContext.Current.Request.ApplicationPath;
}
return strURL;
}
How to Call Json from script to Controller.
function AlreadyExists(varName) {
var dataToSend =
{
Parameter: varName
};
$.ajax({
url: "@UrlPath/Controller/ActionName",
type: "GET",
data: dataToSend,
cache: false,
success: function (data) {
getResult set from data.
}
}
// Controller.
public JsonResultActionName(string Parameter)
{
List
li.Add("2");
li.Add("1");
li.Add("3");
return Json(li, JsonRequestBehavior.AllowGet);
}
2) How to Create Partial view and How to load over the Json.
Loading View :
==================================================
====================
Controller
====================
public ActionResult ActionResultName()
{
return PartialView("_PartialViewName");
}
Partial view Name
=================
3) Get Check Box True or False from Jquery
$(function () { $('#CheckboxName').click(function () {
var getStatus = $('#CheckboxName').is(':checked');
}); });
1) How to disable checkbox grid column in MVC 3
grid1.Column(header: "Select All",
format:
(item) => @Html.Raw(" + ((item.IS_ACTIVE == true)
? "checked" : "") + "
disabled='disabled' />")),
2 2)
How to get selected value
from webgrid in single short
var
getSelectedValues = $("input[name=CheckBoxName]:checked").map(function () { return this.value; }).get().join(",");
3 3)
How to check all checkbox from web grid (“select
all in Header column)
$(function () {
$("#allboxPop").click(function () {
$(".CheckBoxStyleName").attr("checked", $(this).attr("checked") ? true
: false);
});
});
4 4)
How to get selecting checkbox is true or false
in Query
var getStatus = $('#CheckBoxId’).is(':checked');
5) $(function
() {
$('#CheckBoxId’).click(function () {
$("#Dirty").val(true);
});
});
6) To Check page validation in MVC
$("frmName").submit(function () {
if (!$(this).valid()) {
return false;
}
else {
return true;
}
});
$("frmName").submit(function () {
if (!$(this).valid()) {
return false;
}
else {
return true;
}
});
7) How to use post method in JQuery (calling Post.Method with JQuery)
varUrl = "@SolutionName.Controllers.Utils.getAppBaseURL()/ControllerName/ActionResult";
$.post(varUrl, $("#frmName").serialize());
varUrl = "@SolutionName.Controllers.Utils.getAppBaseURL()/ControllerName/ActionResult";
$.post(varUrl, $("#frmName").serialize());
function Changes(_this) { var get = $("#HtmlID option:selected").text(); here we call Json activities. }
@Html.DropDownListFor(model => model.ID, new SelectList(ViewBag.dDDetails, "Value", "Text"), new { @onchange = "Changes(this)", style = "width:257px;"" })
9) How to Bind dropdown value.
View Part:
@Html.DropDownListFor(model => model.ID, new SelectList(ViewBag.dDDetails, "Value", "Text"), new { @onchange = "Changes(this)", style = "width:257px;"" })
Controller Part:
lDetails = (from DataRow row in dtTable.Rows select new modelClass { ID = row["ID"].ToString(), Desc = row["DESC"].ToString() }).ToList();
var dDlDetails = new SelectList(lDetails, "ID", "Desc", selected); ViewBag.dDDetails = dDlDetails;
10) How to Bind Multi List dropdown value:
ViewPart :
@Html.ListBoxFor(model => model.SelectedAvailable, new MultiSelectList(Model.ListAvailable,
"StrAvailableID", "StrAvailableName", Model.SelectedAvailableSource), new { size = "6" })
Controller Part :
var getAvailable = (from avail in vales.AsEnumerable() select new modelClass { StrAvailableID = avail.StrAvailableID, StrAvailableName = avail.StrAvailableName }).ToList();
objDestination.ListAvailable = getAvailable.ToList();
@Html.TextBox("MIN", "", new { style = "width:150px", id = "MIN" }) @Html.TextBox("MAX", "", new { style = "width:150px", id = "MAX" })
function calculation() { var getMin = $("#MIN").val(); var minInt = parseInt(getMin); var getMax = $("#MAX").val(); var maxInt = parseInt(getMax); if (minInt > maxInt) { alert("Should be Greater Than to Min Value"); return false; } return false; }
Static Menu
| @{
var Parentmenus = new[]
{
new { LinkText="Home", ActionName="Index",ControllerName="Home",Roles="1" },
new { LinkText="About", ActionName="About",ControllerName="Home",Roles="2" },
new { LinkText="Contact", ActionName="Contact",ControllerName="Home",Roles="3" },
};
var menus = new[]
{
new { LinkText="Dashboard", ActionName="Index",ControllerName="Dealer",Roles="1" },
new { LinkText="Dashboard", ActionName="Index",ControllerName="Admin",Roles="2" },
new { LinkText="Administration", ActionName="GetUsers",ControllerName="Admin",Roles="2" },
new { LinkText="My Profile", ActionName="GetDealerInfo",ControllerName="Dealer",Roles="3" },
new { LinkText="Products", ActionName="GetProducts",ControllerName="Product",Roles="1" },
new { LinkText="Search", ActionName="SearchProducts",ControllerName="Product",Roles="2" },
new { LinkText="Purchase History", ActionName="GetHistory",ControllerName="Product",Roles="3" },
};
} |




No comments:
Post a Comment