c# - ASP .Net MVC 简单任务
问题描述
我对一项任务有疑问:当用户进入主页时,请查看表单以输入数字和按钮“回答”
当用户给出数字并按下按钮后,用户会收到信息:
- 如果数字是偶数,则为“是”
- 如果数字不均匀,则为“否”
这是一个Index.cshtml
@model WebApplication10.Models.PersonModel
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
<table cellpadding="0" cellspacing="0">
<tr>
<th colspan="2" align="center">Give number</th>
</tr>
<tr>
<td>
@Html.TextBoxFor(m => m.Number)
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Answer" /></td>
</tr>
</table>
}
</body>
</html>
这是我的PersonModel.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebApplication10.Models
{
public class PersonModel
{
///<summary>
/// Gets or sets PersonId.
///</summary>
public int Number { get; set; }
}
}
和HomeController
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication10.Models;
namespace WebApplication10.Controllers
{
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
[ HttpPost]
public ActionResult Index(PersonModel person)
{
return View(person);
}
}
}
我是初学者,ASP .Net MVC
真的,我不知道怎么做,我做了一个按钮,但我不知道应该在哪里以及如何做一个检查数字的功能>>
解决方案
如果这正是您想要的,但我补充说;
<td>
@Html.TextBoxFor(m => m.Number)
@Html.DisplayFor(m => m.IsEven)
</td>
和
public class PersonModel
{
///<summary>
/// Gets or sets PersonId.
///</summary>
public int Number { get; set; }
public string IsEven { get { return Number % 2 == 0 ? "Even" : "Odd"; } }
}
推荐阅读
- arrays - 在数组计算中替换 numpy 数组循环
- image-processing - Pytorch - 迁移学习教程中图像预处理的目的
- c# - 没有 api 和 unicode 的 C# Google 翻译
- sql-server - SQL Server 中的日期时间输入,Node.js 超出范围
- ssl - 在哪里安装 SSL?
- css - 如何通过角度边界值设置背景颜色
- botframework - 使用 botframework rest-api 将 .txt、.pdf 或 zip 文件附加到 Skype 机器人
- c# - 石英调度程序作业未触发?
- r - 如何将导航箭头添加到 rmarkdown ioslide?
- postgresql - 使用 JOOQ 工具强制 PostgreSQL 类型转换