我想在我的index.cshtml和welcome.cshtml頁面之間爲性別(gender.cshtml)創建一個下拉列表,我該怎麼做。另一個問題是,當有人在gender.cshtml頁面中選擇他們的性別時,我可以如何讓它顯示在welcome.cshtml頁面中。例如,如果某人選擇了男性,它就會顯示爲WELCOME「在索引文本框中輸入的姓名」,他是男性。C#MVC DropDownList
HomeController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data.Entity;
using Newproject.Models;
namespace Newproject.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Gender()
{
return View();
}
public ActionResult Welcome(string SearchString)
{
ViewBag.Name = SearchString;
return View();
}
}
}
Index.cshtml
@{
ViewBag.Title = "Welcome";
}
<br />
@Html.Label("Name")
<br />
@using (Html.BeginForm("Welcome", "Home", FormMethod.Post))
{
@Html.TextBox("SearchString");
<input id="btnSubmit" name="btnSubmit" placeholder="test" type="submit" value="Search" />
}
USER.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Newproject.Models
{
public class User
{
public string SearchString { get; set; }
}
}
Gender.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Newproject.Models
{
public class Gender
{
public string Name { get; set; }
}
}
Gender.cshtml
@{
ViewBag.Title = "Gender";
}
<h2>Gender</h2>
Welcome.cshtml
@{
ViewBag.Title = "Welcome";
string CustNo = ViewBag.Name;
}
<p>Welcome @CustNo</p>
這是什麼 「在我index.cshtml和welcome.cshtml頁面之間的」 連是什麼意思? –
哪裏*確切*你想要這個下拉列表? –
在homecontroller.cs中顯示的索引視圖頁面和歡迎查看頁面之間,只需一個包含男性和女性的下拉列表,當客戶選擇他/她所顯示的性別時,會顯示在使用會話的歡迎查看頁面中 – LohithT