我对 MVC 相当陌生。尝试实现剑道编辑器功能。我在 SQL Server 中有一个存储过程,它返回已保存的字符串类型的响应。在后端,它被保存为带有标签的 html 内容。我创建了一个具有以下属性的模型。我试图在控制器中使用相同的属性,但不知为什么我无法访问控制器中的属性。有人可以指出我正确的方向吗?提前致谢。
模型:
public class LargetextQuestion
{
[AllowHtml]
public string Response { get; set; }
}
控制器:
[HttpGet]
public ActionResult Largetext()
{
HsipLargetextQuestionViewModel vm = new HsipLargetextQuestionViewModel();
var result = hsiplargetextquestionrepository.GetLargeTextdata(cRegion, cStateCode, nFY, reportId, sectionId, subsectionId, displayNumber, questionNumber, questionPartNumber, userId);
vm.Response = result;
return View(vm);
[HttpPost]
public ActionResult Largetext(HsipLargetextQuestionViewModel model)
{
try
{
hsiplargetextquestionrepository.SaveLargetextResponse(cRegion, cStateCode, nFY, reportId, sectionId, subsectionId, displayNumber, questionNumber, questionPartNumber, responseString, userId);
return Content("Saved");
}
catch (Exception e)
{
return null;
}
}
视图模型:
private IHsipLargetextQuestionsrepository hsiplargetextquestionrepository;
#region Properties
[Required]
[AllowHtml]
[MaxLength(500, ErrorMessage = "You must enter less than 500 characters.")]
public string Response { get; set; }
public decimal QuestionNumber { get; set; }
#endregion
public HsipLargetextQuestionViewModel()
{ }
public HsipLargetextQuestionViewModel(IHsipLargetextQuestionsrepository repo)
{
this.hsiplargetextquestionrepository = repo;
}
当我进行保存时,记录不会被保存并更新到数据库中。有人可以指出我正确的方向。
谢谢你,哈里