0
我試過幾種不同的方式是將數據從視圖移動到控制器以排序新視圖,但我無法獲取數據通過。以下是我有:傳遞數據查看到控制器
查看1
@model TabCheckout.checkout
@{
ViewBag.Title = "Select the Letter of Your Last Name";
}
<h3>Select the Letter of Your Last Name</h3>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
<div class="col-md-10">
@{int i = 0;
foreach (string letter in ViewBag.Letters)
{
i++;
if (i == 9)
{
i = 0;
@Html.Raw("<br />")
}
else
{
<input type='submit' id='@letter' name='selectletter' value='@letter' formaction='Names' />
}
}
}
</div>
</div>
</div>
}
控制器
public ActionResult Letters(string selectletter)
{
List<string> letters = new List<string>();
for (int y = 0; y < 26; y++)
{
char filter = Convert.ToChar(65 + y);
string letter = filter.ToString();
letters.Add(letter);
}
ViewBag.Letters = letters;
GlobalVariable.selectletter = Convert.ToString(selectletter);
return View(GlobalVariable.selectletter);
}
public ActionResult Names()
{
// var namesrt = from s in db.users
// select s;
// namesrt = namesrt.Where(s => s.LastName.StartsWith(GlobalVariable.letter));
// ViewBag.UserID = new SelectList(namesrt, "UserID", "FullName", null);
ViewBag.UserID = new SelectList(db.users, "UserID", "FullName", null);
return View();
}
查看2
@model TabCheckout.checkout
@{
ViewBag.Title = "Select Your Name";
}
<h3>Select Your Name - @GlobalVariable.selectletter</h3>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
<div class="col-md-10">
@{int i = 0;
foreach (var item in ViewBag.UserID as SelectList)
{
i++;
if (i == 9)
{
i = 0;
@Html.Raw("<br />")
}
else
{
<input type="submit" name="@item.Text" value="@item.Text" formaction="Vehicles">
}
}
}
</div>
</div>
</div>
}
I F鰻魚喜歡大多數問題必須與我的控制語言。我已經嘗試使用請求名稱字符串,FormCollection和當前混亂。
感謝您的幫助和您對我有限的技能水平的理解。
這裏是完全公開的模型:
型號
namespace TabCheckout
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
[Table("NewsData_Tab.checkout")]
public partial class checkout
{
public int CheckoutID { get; set; }
[Required]
public int User { get; set; }
[ForeignKey("User")]
public virtual user users { get; set; }
[Required]
public int Vehicle { get; set; }
[ForeignKey("Vehicle")]
public virtual vehicle vehicles { get; set; }
[Required]
public int Equipment { get; set; }
public DateTime TimeOut { get; set; }
public DateTime TimeIn { get; set; }
public checkout()
{
TimeOut = DateTime.Now;
}
}
public static class GlobalVariable
{
public static string selectletter { get; set; }
}
}
請注意,模型 - 視圖 - 控制器標籤是關於模式的問題。 ASP.NET-MVC實現有一個特定的標籤。 –