Similar to TextChanged Event in ASP.NET MVC

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";

    @Html.TextBoxFor(m => Model.result)
<script src="~/Scripts/jquery-1.10.2.js"></script>
    $(function () {
        $("#SecondNumber").blur(function () {
            $("#result").val(parseInt($("#FirstNumer").val()) + parseInt($("#SecondNumber").val()))
Similar to TextChanged Event in ASP.NET MVC Similar to TextChanged Event in ASP.NET MVC Reviewed by Jacob Lefore on April 29, 2016 Rating: 5

No comments