AspNet MVC4 教育-28:Asp.Net MVC4 Ajax技术部门四舍五入余速Demo
A.创建一个Basic项目类型。
B.于Models创建一个文件夹:
DivModel.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations; namespace MvcAjaxDivTest.Models
{
public class DivModel
{
[Required(ErrorMessage = "请输入一个整数.")]
public int Dividend {set; get;}
[Required(ErrorMessage = "请输入一个整数.")]
public int Divisor {set; get;}
public int? Answer { set; get; }
public int? Remainder { set; get;}
}
}
C.创建HomeController.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcAjaxDivTest.Models; namespace MvcAjaxDivTest.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/ public ActionResult Index()
{
return View();
}
public ActionResult Div(DivModel m)
{
if (m.Divisor == 0)
{
return Json(new { DivisorTip = "除数不能为0", Answer = "", Remainder = "" }, JsonRequestBehavior.AllowGet);
}
return Json(new { DivisorTip= "", Answer = m.Dividend / m.Divisor, Remainder = m.Dividend % m.Divisor }, JsonRequestBehavior.AllowGet);
}
}
}
D.创建对应的Home/Index.cshtml:
@model MvcAjaxDivTest.Models.DivModel
@{
ViewBag.Title = "Ajax Div Test";
}
<h2>Ajax Div Test</h2>
@using (Ajax.BeginForm("Div", "Home", new AjaxOptions {OnSuccess = "ShowResult"}))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>DivModel</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Dividend)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Dividend)
@Html.ValidationMessageFor(model => model.Dividend)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Divisor)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Divisor)<span id="DivisorTip"></span>
@Html.ValidationMessageFor(model => model.Divisor)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Answer)
</div>
<div id="Answer" class="editor-field">
@Html.DisplayFor(model => model.Answer)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Remainder)
</div>
<div id="Remainder" class="editor-field">
@Html.DisplayFor(model => model.Remainder)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
@*<script src="/Scripts/jquery-1.7.1-vsdoc.js" type="text/javascript"></script>*@
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script language="javascript" type="text/javascript">
function ShowResult(data) {
$("#DivisorTip").html(data.DivisorTip);
$("#Answer").html(data.Answer);
$("#Remainder").html(data.Remainder);
}
</script>
}
E.效果示范:
版权声明:本文博主原创文章,博客,未经同意不得转载。
AspNet MVC4 教育-28:Asp.Net MVC4 Ajax技术部门四舍五入余速Demo的更多相关文章
- AspNet MVC4 教学-22:Asp.Net MVC4 Partial View 技术高速应用Demo
A.创建Basic类型的MVC项目. B.Model文件夹下,创建文件: LoginModel.cs: using System; using System.Collections.Generic; ...
- AspNet MVC4 教学-23:Asp.Net MVC4 Display And Editor 模板技术高速应用Demo
A.创建Basic类型的项目. B.在Model文件夹下,创建3个文件: Role.cs: using System; using System.Collections.Generic; using ...
- AspNet MVC4 教学-27:Asp.Net MVC4 自己定义helper及function的高速Demo
A.创建Basic类型项目. B.创建App_Code目录,在里面创建2个cshtml文件: MyHelper.cshtml: @helper MyTruncate(string input, int ...
- ASP.NET中AJAX的异步加载(Demo演示)
此次的Demo是一个页面,页面上有两行字,然后后面用AJAX,使用一个下拉框去替换第一行文字 第一个是被替换的网页 <!DOCTYPE html> <html> <hea ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(28)-系统小结
原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(28)-系统小结 我们从第一节搭建框架开始直到二十七节,权限管理已经告一段落,相信很多有跟上来的园友,已经 ...
- 如何构建ASP.NET MVC4&JQuery&AJax&JSon示例
背景: 博客中将构建一个小示例,用于演示在ASP.NET MVC4项目中,如何使用JQuery Ajax. 步骤: 1,添加控制器(HomeController)和动作方法(Index),并为Inde ...
- Asp.net MVC4 Step By Step(4)-使用Ajax
Ajax技术就是利用Javascript和XML技术实现这样的效果, 可以向Web服务器发送异步请求, 返回更新部分页面的数据, 而不需要全部更新整个页面. Ajax请求两种类型的内容, 一种是服务端 ...
- SignalR + KnockoutJS + ASP.NET MVC4 实现井字游戏
1.1.1 摘要 今天,我们将使用SignalR + KnockoutJS + ASP.NET MVC实现一个实时HTML5的井字棋游戏. 首先,网络游戏平台一定要让用户登陆进来,所以需要一个登陆模块 ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(1)-前言与目录(持续更新中...)
转自:http://www.cnblogs.com/ymnets/p/3424309.html 曾几何时我想写一个系列的文章,但是由于工作很忙,一直没有时间更新博客.博客园园龄都1年了,却一直都是空空 ...
随机推荐
- .Net C# Windows Service于server无法启动,错误 193:0xc1
1.情况说明:的近期发展windows维修,当地win7系统正常.把server安装会失败. 图中的引导失败的例子.: 解决方法:执行->输入:eventvwr.msc 打开你的事件查看器 ...
- 4句代码读取Excel到DataSet(非Excel组件)
Toxy是继NPOI之后主推的还有一个项目,主要目的是为了解决文档的抽取问题.其支持的格式包括全部docx.xlsx.xls.csv.vcard等. 以下是一个简单但非常实用的样例 ParserCon ...
- linux tomcat部署含有matlab画图打包的java web程序
首先说下问题:matlab可以把相关算法代码打包成jar文件共java调用,本例使用的jar文件的作用是画图并保存,然后部署在linux的tomcat中进行发布.这里出现了一个问题,具体如下:linu ...
- Instruments的使用 逻辑查错,内存泄漏分析等工具集
原创文章,转载请注明 XCode 开发后期,要对代码进行改进和优化,查内存泄漏是其中一项重要工作,今天下午偷了点时间,把前段时间的代码稍微整理了一下,顺带用了下这个工具,还真发现了些问题.这里记录一下 ...
- 一百万数据索引实例測试--mysql
推荐书籍:http://pan.baidu.com/s/1sjJIyRV 任务描写叙述: 如果一高频查询例如以下 SELECT * FROM user WHERE area='amoy' AND s ...
- php如何判断用户是从指定页面跳转进来的
$_SERVER['HTTP_REFERER']下'HTTP_REFERER' 引导用户代理到当前页的前一页的地址(如果存在).由 user agent 设置决定.并不是所有的用户代理都会设置该项,有 ...
- Hbase0.96源码之HMaster(二)Hmaster主要循环becomeActiveMaster
1,Hmaster主循环主要这里主要有: 1,1 becomeActiveMaster(startupStatus); 1.2 finishInitialization 1.3 loop() beco ...
- LoadImage()使用
该系统被定义: WINUSERAPIHANDLEWINAPILoadImageA( HINSTANCE, LPCSTR, UINT, int, int, UINT) ...
- Delphi XE7 发布时间
Delphi7 XE7 我可以下载: http://altd.embarcadero.com/download/radstudio/xe7/delphicbuilder_xe7_win.iso 安装包 ...
- easyui LinkButton
http://www.zi-han.net/case/easyui/menu&button.html