自己闲来没事写了个九九乘法表 ,新手入门。大家…

2018-06-22 06:16:08来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

自己闲来没事写了个九九乘法表 ,新手入门。

 1 @using WebApp_Mvc_Wg_Api.Controllers;
 2 @{
 3     ViewBag.Title = "九九乘法表";
 4     //Layout = "~/Views/Shared/_Layout.cshtml";
 5 }
 6 <style>
 7     .main {
 8         width: 1000px;
 9         height:190px;
10     }
11 
12         .main li {
13             float: left;
14             width: 100px;
15             list-style: none;
16         }
17 </style>
18 <h2>@ViewBag.Title</h2>
19 
20 <div class="main">
21     @{
22         List<string> cf_list = ViewData["chenfabiao"] as List<string>;
23     }
24     <ul>
25         @foreach (var item in cf_list)
26         {
27             <li>@item.ToString()</li>
28         }
29     </ul>
30 </div>
31 
32 <hr />
33 
34 <h2>九九加法表</h2>
35 
36 <div class="main">
37     @{
38         List<string> jf_list = ViewData["jiafabiao"] as List<string>;
39     }
40     <ul>
41         @foreach (var item in jf_list)
42         {
43             <li>@item.ToString()</li>
44         }
45     </ul>
46 </div>
View Code
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.Web.Mvc;
 6 
 7 namespace WebApp_Mvc_Wg_Api.Controllers
 8 {
 9     public class DemoController : Controller
10     {
11         // GET: Demo
12         public ActionResult Index()
13         {
14             return View();
15         }
16         public ActionResult chenfabiao()
17         {
18             jiafabiao();
19 
20             List<string> list = new List<string>();
21             for (int x = 1; x <= 9; x++)
22             {
23                 for (int y = 1; y <= 9; y++)
24                 {
25                     string formula = y + " * " + x + " = " + (x * y);
26                     formula = y > x ? "" : formula;
27                     list.Add(formula);
28                 }
29             }
30             ViewData["chenfabiao"] = list.ToList();
31             return View(ViewData["chenfabiao"]);
32         }
33 
34         public ActionResult jiafabiao()
35         {
36             List<string> list = new List<string>();
37             for (int x = 1; x <= 9; x++)
38             {
39                 for (int y = 1; y <= 9; y++)
40                 {
41                     string formula = y + " + " + x + " = " + (x +y);
42                     formula = y > x ? "" : formula;
43                     list.Add(formula);
44                 }
45             }
46             ViewData["jiafabiao"] = list.ToList();
47             return View(ViewData["jiafabiao"]);
48         }
49        
50     }
51 }
Controllers Code

页面结构

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:asp.net mvc webapi 实用的接口加密方法

下一篇:EF的使用