本文介绍了我想在索引视图中获取classid。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
i need dropdown list of my class tablein my index view when i use viewbag method but it still show error in my index view ClassID,how i can remove this issue plz some one help me..
我尝试过:
What I have tried:
THIS IS MY iNDEX VIEW.
@using PagedList;
@using PagedList.Mvc;
@model PagedList.IPagedList<opr.Data.C_QuestionTable>
@model opr.Data.myclass
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<div class="alert-success form-control m-auto w-75 custom-form">
<div class="col-6 pb-3 input-control">
<label for="ex3"> Select Class:</label>
@Html.DropDownListFor(model => model., (SelectList)ViewBag.dataForDropDowns, new { @class = "form-control select2ddl" })
</div>
<p>
@Html.ActionLink("Create New", "Create")
</p>
</div>
this my controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using opr.Data;
using PagedList;
using PagedList.Mvc;
namespace opr.Controllers
{
public class OnlineQuizeController : Controller
{
examsEntities db = new examsEntities();
public ActionResult Index(int?page)
{
var mod1 = db.myclasses.Select(s => new { s.ID, s.C_name }).ToList();
SelectList sList = new SelectList(mod1, "ID", "C_name");
ViewBag.dataForDropDown = sList;
List<object> myobject = new List<object>();
myobject.Add(db.myclasses.ToList());
ViewBag.classIDs = myobject;
var pageNumber = page ?? 1;
var pageSize = 3;
var question = db.C_QuestionTable.OrderBy(x => x.QuestionText).ToPagedList(pageNumber, pageSize);
return View(question);
}
}
}
推荐答案
@model Popr.Data.C_QuestionTable
现在你应该可以进入酒店了:
and now you should be able to access the property :
<pre> @Html.DropDownListFor(model => model.ClassID, (SelectList)ViewBag.dataForDropDowns, new { @class = "form-control select2ddl" })
这篇关于我想在索引视图中获取classid。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!