I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component public class AllViewComponent : ViewComponent { private readonly UserManager<ApplicationUser> _userManager; public AllViewComponent(UserManager<ApplicationUser> userManager) { _userManager = userManager; } public async Task<IViewComponentResult> InvokeAsync() { List<StudentViewModel> allUsers = new List<StudentViewModel>(); var items = await _userManager.Users.ToListAsync(); foreach (var item in items) { allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email }); }
This is very good article for web form users who want to get value on TextChanged Event. I mean to say that TextChanged Event occurs when we move one textbox to another using "Tab" key. When, Web form users moves to MVC projects. He/ She faces some problems in logics. Because, in MVC, For each request we must to call controller. I have an idea to remove such task. I prefer JQuery. So first to Add a ViewModel Class into your project. You can take this sample.
1. Add a new Folder in your project, name of the folder is "viewModel". Now, add a class, which name as addition like
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebApplication27.viewModel
{
public class addition
{
public int FirstNumer { get; set; }
public int SecondNumber { get; set; }
public int result { get; set; }
}
}
In this we have three public property.Now, Add a controller class in Controller folder. Like that.
using System.Web.Mvc;
namespace WebApplication27.Controllers
{
public class DefaultController : Controller
{
// GET: Default
public ActionResult Index()
{
return View();
}
}
}
Add View, By using Right click on Action method name. In View section, i will add code of JQuery. You can see
@model WebApplication27.viewModel.addition
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@using(Html.BeginForm())
{
@Html.TextBoxFor(m=>Model.FirstNumer)
@Html.TextBoxFor(m=>Model.SecondNumber)
@Html.TextBoxFor(m => Model.result)
}
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script>
$(function () {
$("#SecondNumber").blur(function () {
$("#result").val(parseInt($("#FirstNumer").val()) + parseInt($("#SecondNumber").val()))
});
})
</script>
1. Add a new Folder in your project, name of the folder is "viewModel". Now, add a class, which name as addition like
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebApplication27.viewModel
{
public class addition
{
public int FirstNumer { get; set; }
public int SecondNumber { get; set; }
public int result { get; set; }
}
}
In this we have three public property.Now, Add a controller class in Controller folder. Like that.
using System.Web.Mvc;
namespace WebApplication27.Controllers
{
public class DefaultController : Controller
{
// GET: Default
public ActionResult Index()
{
return View();
}
}
}
Add View, By using Right click on Action method name. In View section, i will add code of JQuery. You can see
@model WebApplication27.viewModel.addition
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@using(Html.BeginForm())
{
@Html.TextBoxFor(m=>Model.FirstNumer)
@Html.TextBoxFor(m=>Model.SecondNumber)
@Html.TextBoxFor(m => Model.result)
}
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script>
$(function () {
$("#SecondNumber").blur(function () {
$("#result").val(parseInt($("#FirstNumer").val()) + parseInt($("#SecondNumber").val()))
});
})
</script>
Comments
Post a Comment