运行时错误“无法将类型X的对象强制转换为Y”

时间:2014-10-23 12:52:37

标签: c# asp.net-mvc asp.net-mvc-4 razor

控制器:

[NopHttpsRequirement(SslRequirement.No)]
public ActionResult TicketReply(Guid uniqueTicketId   )
{
    var ticketReplyModel = new BsTicketReplyModel();
    var bsTicket = _bsTicketService.GetBsTicketByUniqueTicketId(uniqueTicketId);
    ticketReplyModel.BsTicket = bsTicket.ToModel();

    ticketReplyModel.DisplayCaptcha = true;
    return View("BsTicketDetails", ticketReplyModel);

}

[HttpPost]
public ActionResult TicketReply(BsTicketReplyModel model)
{
          ....
    return View("BsTicketDetails", model);
}

路线:

routes.MapRoute("Nop.Plugin.BrainStation.HelpDesk.TicketDetails", "HelpDesk/TicketReply/{uniqueTicketId}",
                new { controller = "BsHelpDesk", action = "TicketReply", uniqueTicketId = UrlParameter.Optional },
                new[] { "Nop.Plugin.BrainStation.HelpDesk.Controllers" });

            routes.MapRoute("Nop.Plugin.BrainStation.HelpDesk.TicketReply", "HelpDesk/TicketReply/Submit",
                new { controller = "BsHelpDesk", action = "TicketReply"},
                new[] { "Nop.Plugin.BrainStation.HelpDesk.Controllers" });

Razor Cshtml:

@using Nop.Plugin.BrainStation.HelpDesk.Models
@using Nop.Web.Framework
@model BsTicketReplyModel
@using Nop.Core.Domain.Seo;
@using Nop.Core.Infrastructure;
@using Nop.Web.Models.Catalog;
@using Nop.Web.Framework.UI
@using Nop.Web.Framework.UI.Captcha

@using (Html.BeginForm("Submit", "HelpDesk/TicketReply", FormMethod.Post, new { enctype = "multipart/form-data"}))
{
    ......
}

我在运行时收到此错误。我在 [HttpPost] 上得到了一个调试器点。但它没有被击中。但与此同时发生了这个错误。并且问题在流利的验证中显示。有什么问题?提前感谢

无法将“Nop.Plugin.BrainStation.HelpDesk.Models.BsTicketReplyModel”类型的对象转换为“Nop.Plugin.BrainStation.HelpDesk.Models.BsTicketCreateModel”。

enter image description here

0 个答案:

没有答案