C# MVC单选之后传值问题 5C

我现在帮一个在线自动打分的程序,model
using BrnMall.Core;
using BrnMall.Services;
using BrnMall.Web.Framework;

namespace BrnMall.Web.MallAdmin.Models
{
public class ExamModel
{

    public int classID { get; set; }


    /// <summary>
    /// 描述
    /// </summary>
    public string Name { get; set; }
    public DateTime CreateDate { get; set; }
    public string url { get; set; }
    public int ecount { get; set; }
}

public class ExamListModel
{

    public PageModel PageModel { get; set; }
    /// <summary>
    /// 广告位置列表
    /// </summary>
    public List<ExamInfo> ExamList { get; set; }
}
public class ExamshowListModel
{
    public PageModel pageModel;
    public int classID { get; set; }
    public int Id { get; set; }

    public List<AnswerInfo> showanlist { get; set; } //回答问题的列表
    /// <summary>
    /// 描述
    /// </summary>
    public string Name { get; set; }

    public string url { get; set; }
    public int ecount { get; set; }
    public List<ExercisesInfo> ExercisesList { get; set; }//题目列表

}

}
View
@model BrnMall.Web.MallAdmin.Models.ExamshowListModel

@section header{

进入查看详情


<script type="text/javascript" src="/admin_mall/scripts/jquery.validate.js"></script>
<script type="text/javascript" src="/admin_mall/scripts/jquery.validate.unobtrusive.js"></script>

}

@section body{

>>

@using (Html.BeginForm())
{
@Html.HiddenFor(m => m.Id)
@Html.HiddenFor(m => m.classID)
@Html.HiddenFor(m => m.Name)
@Html.HiddenFor(m => m.ecount)

@for (int i = 0; i m.ExercisesList[i].id) @Html.HiddenFor(m => m.showanlist[i].Id) if (info.type == 1) { //单选 @Html.ValidationMessageFor(m => m.showanlist[i]) @Html.HiddenFor(m => m.showanlist[i]) } else if (info.type == 2) {//多选 } else if (info.type == 3) {//判断 } else if (info.type == 4) {//简答 } } @Html.HiddenFor(m => m.showanlist) @Html.HiddenFor(m => m.ExercisesList)
题目: @Html.TextBoxFor(x => x.Name, new { @class = "input", size = "35" })@Html.ValidationMessageFor(x => x.Name)
题目: @info.title
A: @Html.RadioButtonFor(m => m.showanlist[i].A, Model.showanlist[i].Id, new { @id = Model.showanlist[i].Id.ToString(), @name = Model.showanlist[i].Name.ToString() }) @Html.ValidationMessageFor(m => m.showanlist[i].A) @Model.ExercisesList[i].A
B: @Html.RadioButtonFor(m => m.showanlist[i].A, aninfo.Id, new { @id = aninfo.Id.ToString(), @name = aninfo.Name.ToString() }) @Html.ValidationMessageFor(m => m.showanlist[i].A)@Model.ExercisesList[i].B
C: @Html.RadioButtonFor(m => m.showanlist[i].A, aninfo.Id, new { @id = aninfo.Id.ToString(), @name = aninfo.Name.ToString() }) @Html.ValidationMessageFor(m => m.showanlist[i].A)@Model.ExercisesList[i].C
D: @Html.RadioButtonFor(m => m.showanlist[i].A, aninfo.Id, new { @id = aninfo.Id.ToString(), @name = aninfo.Name.ToString() }) @Html.ValidationMessageFor(m => m.showanlist[i].A)@Model.ExercisesList[i].D
A: @info.A
B: @info.B
C: @info.C
D: @info.D
A: @info.A
B: @info.B
A: @info.A
  提交 $(function () { $("#sumbitBut").click(function () { $("form:first").submit(); return false; }) });
   
}

}

Controller
[HttpGet]
public ActionResult Edit(int storeRid = -1)
{
ExamInfo storeRankInfo = Exam.GetExamById(storeRid);
if (storeRankInfo == null)
return PromptView("试题不存在");
string url = storeRankInfo.url;
DataTable dt1 = new DataTable();
dt1.ReadXml(url);

        //////////取出URL
        ////////URL生成题


        ExamshowListModel model = new ExamshowListModel();
        model.classID = storeRankInfo.classID;
        model.Id = storeRankInfo.Id;
        model.ecount = storeRankInfo.ecount;
        List<ExercisesInfo> infolist=new List<ExercisesInfo>();
        List<AnswerInfo> anlist = new List<AnswerInfo>();
        foreach (DataRow row in dt1.Rows) {
            ExercisesInfo info = new ExercisesInfo();
            AnswerInfo aninfo = new AnswerInfo();
            info.id = TypeHelper.ObjectToInt(row["Id"]);
            info.type = TypeHelper.ObjectToInt(row["type"]);
            info.title=row["title"].ToString();
            info.A = row["A"].ToString();
            info.B = row["B"].ToString();
            info.C = row["C"].ToString();
            info.D = row["D"].ToString();
            info.answer = row["answer"].ToString();
            aninfo.Id = info.id;
            aninfo.Name = "N"+info.id.ToString();
            infolist.Add(info);
            anlist.Add(aninfo);
        }
        model.ExercisesList = infolist;
        model.showanlist = anlist;
        Load();
        return View(model);
    }

接受函数
public ActionResult Edit(ExamshowListModel model, int storeRid = -1)
{

        int id = model.Id;

//这里的 model.showanlist.Count为0,无法收到结果。
for (int i = 0; i <= model.showanlist.Count-1;i++ ){
string s=model.showanlist[i].A;

        }


        Load();
        return View(model);
    }
c#
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐