【发布时间】:2014-01-17 11:44:39
【问题描述】:
在我的数据第一个 .edmx 文件中,我有一个部分类问题;我创建了一个 ViewModel 来填充我的视图并为我的问题提交表单。
虽然我的提交 ViewModel 工作得很好,但我的 get ViewModel 却得到了一个非常意外的回报。在调试期间,我可以看到我需要的所有数据,但是 ViewModel 也返回了
{System.Data.Entity.DynamicProxies.Question_AC5369E927D7DA13E53B81D39BBD14BEBF05146E3CC12E147A7CB4C32F869EF9}
我和控制器都不知道如何处理。正如我所说,它还返回了我所有其他必填字段,但在第一次奇怪的返回时中断了。
有人有类似的结果吗?
根据要求,我的视图模型;
public class GetQuestionViewModel
{
public class Question {
public Question Questions { get; set; }
public Response Response { get; set; }
}
public GetQuestionViewModel()
{
this.QuestionOptions = new HashSet<QuestionOption>();
this.Responses = new HashSet<Response>();
}
[Key]
public int Id { get; set; }
public int PageNumber { get; set; }
public string Question1 { get; set; }
public int QuestionTypeId { get; set; }
public Nullable<int> LinkedTo { get; set; }
public Nullable<int> Options { get; set; }
public Nullable<int> QuestionRanking { get; set; }
public virtual ICollection<QuestionOption> QuestionOptions { get; set; }
public virtual QuestionType QuestionType { get; set; }
public virtual ICollection<Response> Responses { get; set; }
}
还有行动;
[HttpGet]
public ActionResult ViewQuestion(int? id)
{
if (id == null || id == 0 || id > 13)
{
id = 8;
}
Question question = db.Questions.Find(id);
if (question == null)
{
return HttpNotFound();
}
return View(question);
}
【问题讨论】:
-
您是否以 JSON 格式返回数据?您是否使用/需要延迟加载?
-
我还没有达到那个阶段,但我会的。这是我的第一个 MVC 项目,我仍在努力学习基础知识。
-
向我们展示视图模型,如果可能的话,展示从 EF 上下文构建视图模型的控制器代码
-
我开始认为代理不是这里的问题。你有错误吗?
标签: c# asp.net-mvc viewmodel edmx