下拉列表编辑审核

时间:2016-08-16 22:12:38

标签: c# asp.net-mvc ienumerable

所以我从我的数据库和控制器设置了我的模型和控制器,我已经生成了视图。因此,为了给您一些背景知识,我创建了一个应用程序供用户发布和编辑有关特定服务的评论。我为用户创建了“创建”和“编辑”视图,以创建评论和/或编辑评论。创建视图中的表单组的一部分允许用户选择他们想要查看的服务

<div>
                <div class="form-group">
                    @Html.LabelFor(model => model.WellnessService, htmlAttributes: new { @class = "control-label col-md-2" })
                    <div class="col-md-10">
                        @Html.DropDownList("WellnessService", new List<SelectListItem>
                {
                    new SelectListItem() {Text = "Student Wellness Service", Value = "Student Wellness Service"},
                    new SelectListItem() {Text = "HAICU", Value = "HAICU"},
                    new SelectListItem() {Text = "Student Counceling", Value = "Student Counceling"},
                    new SelectListItem() {Text = "DISCHO ( Discrimination and Harassment  Office)", Value = "DISCHO"},
                    new SelectListItem() {Text = "Campus Protection Service (CPS)", Value = "CPS"},
                    new SelectListItem() {Text = "Disablity Service", Value = "Disability Service"},
                }, "Select Wellness Service")



                        @Html.ValidationMessageFor(model => model.WellnessService, "", new { @class = "text-danger" })
                    </div>
                </div>
            </div>

然而,在编辑视图中,用户可以根据自己的喜好获得服务的价值。我希望用户只根据我给出的下拉列表更改评论的服务名称,而不是键入

<div class="form-group">
                        @Html.LabelFor(model => model.Rating, htmlAttributes: new {@class = "control-label col-md-2"})
                        <div class="col-md-10">
                            @Html.EditorFor(model => model.Rating, new {htmlAttributes = new {@class = "form-control"}})
                            @Html.ValidationMessageFor(model => model.Rating, "", new {@class = "text-danger"})
                        </div>
                    </div>

如果这是有道理的:P

我已经读过你必须在你的模型中设置一个枚举器,但是有指南可用,这是代码首先是mvc5而不是数据库

1 个答案:

答案 0 :(得分:0)

有很多方法可以做到这一点。您的ViewModel中的scala> sc.stop scala> import com.datastax.spark.connector._, org.apache.spark.SparkContext, org.apache.spark.SparkContext._, org.apache.spark.SparkConf import com.datastax.spark.connector._ import org.apache.spark.SparkContext import org.apache.spark.SparkContext._ import org.apache.spark.SparkConf scala> val conf = new SparkConf(true).set("spark.cassandra.connection.host", "localhost") conf: org.apache.spark.SparkConf = org.apache.spark.SparkConf@a9a8ec3 scala> val sc = new SparkContext(conf) sc: org.apache.spark.SparkContext = org.apache.spark.SparkContext@6451a288 scala> val test_spark_rdd = sc.cassandraTable("test_spark", "test") test_spark_rdd: com.datastax.spark.connector.rdd.CassandraTableScanRDD[com.datastax.spark.connector.CassandraRow] = CassandraTableScanRDD[0] at RDD at CassandraRDD.scala:15 scala> test_spark_rdd.first 16/08/16 15:02:19 ERROR Executor: Exception in task 0.0 in stage 0.0 (TID 0) java.lang.NoClassDefFoundError: scala/collection/GenTraversableOnce$class at com.datastax.spark.connector.util.CountingIterator.<init>(CountingIterator.scala:4) at com.datastax.spark.connector.rdd.CassandraTableScanRDD.compute(CassandraTableScanRDD.scala:336) at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:319) at org.apache.spark.rdd.RDD.iterator(RDD.scala:283) at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:70) at org.apache.spark.scheduler.Task.run(Task.scala:85) at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:274) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.ClassNotFoundException: scala.collection.GenTraversableOnce$class at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 10 more 16/08/16 15:02:19 ERROR SparkUncaughtExceptionHandler: Uncaught exception in thread Thread[Executor task launch worker-0,5,main] java.lang.NoClassDefFoundError: scala/collection/GenTraversableOnce$class at com.datastax.spark.connector.util.CountingIterator.<init>(CountingIterator.scala:4) at com.datastax.spark.connector.rdd.CassandraTableScanRDD.compute(CassandraTableScanRDD.scala:336) at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:319) at org.apache.spark.rdd.RDD.iterator(RDD.scala:283) at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:70) at org.apache.spark.scheduler.Task.run(Task.scala:85) at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:274) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.ClassNotFoundException: scala.collection.GenTraversableOnce$class at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 10 more 16/08/16 15:02:19 WARN TaskSetManager: Lost task 0.0 in stage 0.0 (TID 0, localhost): java.lang.NoClassDefFoundError: scala/collection/GenTraversableOnce$class at com.datastax.spark.connector.util.CountingIterator.<init>(CountingIterator.scala:4) at com.datastax.spark.connector.rdd.CassandraTableScanRDD.compute(CassandraTableScanRDD.scala:336) at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:319) at org.apache.spark.rdd.RDD.iterator(RDD.scala:283) at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:70) at org.apache.spark.scheduler.Task.run(Task.scala:85) at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:274) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.ClassNotFoundException: scala.collection.GenTraversableOnce$class at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 10 more 16/08/16 15:02:19 ERROR TaskSetManager: Task 0 in stage 0.0 failed 1 times; aborting job 16/08/16 15:02:19 ERROR LiveListenerBus: SparkListenerBus has already stopped! Dropping event SparkListenerStageCompleted(org.apache.spark.scheduler.StageInfo@12164ec5) 16/08/16 15:02:19 ERROR LiveListenerBus: SparkListenerBus has already stopped! Dropping event SparkListenerJobEnd(0,1471384939706,JobFailed(org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 0.0 failed 1 times, most recent failure: Lost task 0.0 in stage 0.0 (TID 0, localhost): java.lang.NoClassDefFoundError: scala/collection/GenTraversableOnce$class at com.datastax.spark.connector.util.CountingIterator.<init>(CountingIterator.scala:4) at com.datastax.spark.connector.rdd.CassandraTableScanRDD.compute(CassandraTableScanRDD.scala:336) at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:319) at org.apache.spark.rdd.RDD.iterator(RDD.scala:283) at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:70) at org.apache.spark.scheduler.Task.run(Task.scala:85) at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:274) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.ClassNotFoundException: scala.collection.GenTraversableOnce$class at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 10 more Driver stacktrace:)) ,您可以创建一个model并像这样传递

IEnumerable<WellnessService> WellnessService { get; set; }

或者您可以将它放在ViewBag中并像这样传递

var services = new List <SelectListItem> {
    new SelectListItem() {
            Text = "Student Wellness Service", Value = "Student Wellness Service"
        },
        new SelectListItem() {
            Text = "HAICU", Value = "HAICU"
        },
        new SelectListItem() {
            Text = "Student Counceling", Value = "Student Counceling"
        },
        new SelectListItem() {
            Text = "DISCHO ( Discrimination and Harassment  Office)", Value = "DISCHO"
        },
        new SelectListItem() {
            Text = "Campus Protection Service (CPS)", Value = "CPS"
        },
        new SelectListItem() {
            Text = "Disablity Service", Value = "Disability Service"
        },
}
model.WellnessServices = services;