2016-AspNet-MVC教学-1-算术加法提交及超链接测试

启动VS2010平台,新建VC# MVC4 Project,Basic类型

整体构成及Index.cshtml内容:


AddCal.cshtml Code:

@{  
    ViewBag.Title = "AddCal";  
}  
  
<h2>AddCal</h2>  
@using(Html.BeginForm("AddCal","Home"))  
{  
@Html.TextBox("FirstNum") <text>+</text>  
@Html.TextBox("SecondNum")<text>=</text>  
@Html.TextBox("SumNum",(string)ViewBag.SumNum)  
<br />  
<input type="submit" />  
}  

HomeController.cs Code:

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Web;  
using System.Web.Mvc;  
  
namespace MvcAddTest.Controllers  
{  
    public class HomeController : Controller  
    {  
        // GET: /Home/  
        public ActionResult Index()  
        {  
            return View();  
        }  
        public ActionResult AddCal()  
        {  
            ViewBag.SumNum = "";  
            return View();  
        }  
        [HttpPost]  
        public ActionResult AddCal(string FirstNum,string SecondNum)  
        {  
            int a, b,c;  
            a = int.Parse(FirstNum);  
            b = int.Parse(SecondNum);  
            c = a + b;  
            ViewBag.SumNum = c.ToString();  
            return View();  
        }  
    }  
}  

小结:了解提交方式Get及Post的区别.了解前端View与后台Action之间的呼应关系.了解ViewBag传递数据的方法.了解字符串和整数的转换方法.了解Html助记符的写法.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

gCodeTop 格码拓普 老师

您的鼓励.我的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值