ASP.Net Page Method using jQuery AJAX Example
function ShowCurrentTime() {
$.ajax({
type: "POST",
url: "CS.aspx/GetCurrentTime",
data: '{name: "' + $("#<%=txtUserName.ClientID%>")[0].value + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function(response) {
alert(response.d);
}
});
}
function OnSuccess(response) {
alert(response.d);
}
[System.Web.Services.WebMethod]
public static string GetCurrentTime(string name)
{
return "Hello " + name + Environment.NewLine + "The Current Time is: "
+ DateTime.Now.ToString();
}
How to select second div using jQuery in a webpage?
If a webpage has 2 div tags like
<div>hello</div>
<div>hello</div>
$("div:eq(1)");
How do I get the value of a selected item of a radio button list
with jquery
$('#btnTest').click(function()
{
alert($('#<%=RadioButtonList1.ClientID %> input[type=radio]:checked').val());
});
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Text="Yes" Value="1"></asp:ListItem>
<asp:ListItem Text="No" Value="2"></asp:ListItem>
</asp:RadioButtonList>
<input type="button" id="btnTest" value="Uncheck" />
Difference between document.getElementById and document.getElementsByClassName
document.getElementById returns a single DOM element whose ID matches your query.
document.getElementsByClassName returns an
document.getElementsByClassName returns an
HtmlCollection
- an array-like structure containing the DOM elements that matched your query
<div class="move">add padding</div>
<div class="move">add padding</div>
<button type="button" onclick="movefun()">Set left padding</button>
<script>
function movefun() {
var elements = document.getElementsByClassName("move");
for (var i = 0; i < elements.length; i++) {
elements[i].style.paddingLeft = "50px";
}
}
</script>
OUTPUT:add padding
add padding
Display Data In Table Format In MVC
Display Data In Table Format In MVC
Add Employee Class in Model folder.
- class Employee
- {
- public int EmployeeId { get; set; }
- public string FirstName { get; set; }
- public string LastName { get; set; }
- public string Email { get; set; }
- public int Salary { get; set; }
- public string Company { get; set; }
- public string Dept { get; set; }
- }
- public class HomeController : Controller
- {
- private List<Employee> emp;
- public HomeController()
- {
- emp = new List<Employee>()
- {
- new Employee()
- { EmployeeId =1,FirstName="Rakesh",LastName="Kalluri", Email="raki.kalluri@gmail.com", Salary=30000, Company="Summit", Dept="IT" },
- new Employee()
- { EmployeeId =2,FirstName="Naresh",LastName="C", Email="Naresh.C@gmail.com", Salary=50000, Company="IBM", Dept="IT" },
- new Employee()
- { EmployeeId =3,FirstName="Madhu",LastName="K", Email="Madhu.K@gmail.com", Salary=20000, Company="HCl", Dept="IT" },
- new Employee()
- { EmployeeId =4,FirstName="Ali",LastName="MD", Email="Ali.MD@gmail.com", Salary=26700, Company="Tech Mahindra", Dept="BPO" },
- new Employee()
- { EmployeeId =5,FirstName="Chithu",LastName="Raju", Email="Chithu.Raju@gmail.com", Salary=25000, Company="Dell", Dept="BPO" },
- new Employee()
- { EmployeeId =6,FirstName="Nani",LastName="Kumar", Email="Nani.Kumar@gmail.com", Salary=24500, Company="Infosys", Dept="BPO" },
- };
- }
- public ActionResult Index()
- {
- return View(emp);
- }
Index.Cshtml
- @model IEnumerable<List_Data_Binding_in_MVC.Models.Employee>
- @{
- ViewBag.Title = "Index";
- }
- <div><b>Table Format Data Displaying in ForEach</b><br /></div>
- <table class="table table-bordered table-responsive table-hover">
- <tr>
- <th>Employee Id </th>
- <th>First Name </th>
- <th>Last Name </th>
- <th>Email</th>
- <th>Salary</th>
- <th>Company</th>
- <th>Department</th>
- </tr>
- @foreach (var d in Model)
- {
- <tr>
- <td>@d.EmployeeId</td>
- <td>@d.FirstName</td>
- <td>@d.LastName</td>
- <td>@d.Email</td>
- <td>@d.Salary</td>
- <td>@d.Company</td>
- <td>@d.Dept</td>
- </tr>
- }
- </table>
No comments:
Post a Comment