跟網頁上的一個例子學習一個MVC處理表單的例子,怎么搞不定啊?提交了表單沒有效果,就是頁面重繪一下,求助啊!
okController頁面位于Controller檔案夾下,代碼如下================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebApplication1.Models
{
public class okController : Controller
{
//
// GET: /ok/
public ActionResult Index()
{
return View();
}
}
public class person
{
//[Required(ErrorMessage = "請輸入名字")]
public string name { get; set; }
public string email { get; set; }
}
}
LoginController頁面也是在Controller檔案夾下,代碼如下================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebApplication1.Controllers
{
public class LoginController : Controller
{
//
// GET: /Login/
public ActionResult Index()
{
Response.Write("不正確!");
return View();
}
public ActionResult Login()
{
Response.Write("不正確!");
return View();
}
}
}
Index.cshtml位于Views/Home下,代碼如下:==================
@model WebApplication1.Models.person
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>這是一個網頁</title>
</head>
<body>
@using (Html.BeginForm())
{
<p>你的名字:@Html.TextBoxFor(model => model.name)</p>
<p>郵件地址:@Html.TextBoxFor(model => model.email)</p>
<input type="submit" value="https://bbs.csdn.net/topics/提交按鈕" />
}
</body>
</html>
======================代碼完============
提交完了就是頁面重繪一下,我粗學乍練,有點轉向,請各位指教一下怎么才能開始處理,哪怕打出一個 "不正確!"?
uj5u.com熱心網友回復:
Html.BeginForm("ActionName","ControllerName",FormMethod.method)uj5u.com熱心網友回復:
是不是有個action 引數忘記填了,這樣才能知道你表單提交到哪里去了,很久沒用過這玩意。uj5u.com熱心網友回復:
提交給哪個方法的,接收了才能有效果啊,而且跳轉也需要在后臺寫啊uj5u.com熱心網友回復:
我看例子就是這么寫的,他能運行起來,是不是相當于默認為本頁面處理呢?
uj5u.com熱心網友回復:
我改成這樣using (Html.BeginForm("Login","LoginController",FormMethod.Post))提示找不到頁面,哪里錯了?
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/276505.html
標籤:ASP.NET
