发布网友 发布时间:2022-04-08 06:59
共2个回答
懂视网 时间:2022-04-08 11:20
ActionResult vote(int id=1) { //int id = 1; list newlist = db.lists.Find(id); //var q = from p in db.lists where p.id==1 select p; //list newlist = new list { id=q.id}; //var tes = q; return View(newlist); } [HttpPost] public ActionResult vote(list newlist) { //var q = Request.Form["item.id"]; //var p = Convert.ToInt32(Response.Cookies["id"].Value); al newal = new al { uid = Convert.ToInt32(Request.Cookies["id"].Value), lid = newlist.id, result = Request.Form["result"] }; db.als.Add(newal); db.SaveChanges(); int a = newlist.id + 1; list next = db.lists.Find(a); return RedirectToAction("vote", new { id = a }); }@model votesys.list @{ ViewBag.Title = "vote"; } <h2>vote</h2> @using (Html.BeginForm()) { @Html.AntiForgeryToken() @Html.ValidationSummary(true) <fieldset> <legend>list</legend> @Html.HiddenFor(model => model.id) <div class="editor-label"> @Html.LabelFor(model => model.question) </div> <div class="editor-field"> @Html.EditorFor(model => model.question) @Html.ValidationMessageFor(model => model.question) </div> <div class="editor-label"> @Html.LabelFor(model => model.remark) </div> <div class="editor-field"> @Html.EditorFor(model => model.remark) @Html.ValidationMessageFor(model => model.remark) </div> <div> <input type="radio" id="GenderM" name="result" value="公司制度很完善" />选项一 <input type="radio" id="GenderF" name="result" value="人员分配合理" checked />选项二 </div> <p> <input type="submit" value="Save" /> </p> </fieldset> } <div> @Html.ActionLink("Back to List", "Index") </div> @section Scripts { @Scripts.Render("~/bundles/jqueryval") }
MVC同一页面循环显示数据库记录(答题/投票系统)
标签:
热心网友 时间:2022-04-08 08:28
可以直接在控制器中将DataTable返回到对应视图中,也可以将DataTable转换到List中通过ViewData或者ViewBag在对应视图进行调用.