码迷,mamicode.com
首页 > 数据库 > 详细

MVC同一页面循环显示数据库记录(答题/投票系统)

时间:2015-08-11 17:56:11      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:

//控制器代码
public
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同一页面循环显示数据库记录(答题/投票系统)

标签:

原文地址:http://www.cnblogs.com/lovejunjuan/p/4721438.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!