using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace MvcDiv.Models
{
public class DivBox
{
[Display(Name = "被除数")]
public int Dividend { set; get; }
[Display(Name = "除数")]
public int Divisor { set; get; }
[Display(Name = "商")]
public int Answer { set; get; }
[Display(Name = "余数")]
public int Remainder { set; get; }
}
}
using MvcDiv.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcDiv.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult CalDiv(DivBox box)
{
box.Answer = box.Dividend / box.Divisor;
box.Remainder = box.Dividend % box.Divisor;
return View("Index",box);
}
}
}
@model MvcDiv.Models.DivBox
@{
ViewBag.Title = "除法演示";
}
<h2>除法演示</h2>
@using (Html.BeginForm("CalDiv","Home",FormMethod.Post)) {
@Html.ValidationSummary(true)
<fieldset>
<legend>作者:马老师</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)
@Html.ValidationMessageFor(model => model.Divisor)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Answer)
</div>
<div class="editor-field">
@Html.DisplayFor(model => model.Answer)
@Html.ValidationMessageFor(model => model.Answer)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Remainder)
</div>
<div class="editor-field">
@Html.DisplayFor(model => model.Remainder)
@Html.ValidationMessageFor(model => model.Remainder)
</div>
<p>
<input type="submit" value="计算" />
</p>
</fieldset>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}