Mvc模型错误

时间:2014-07-03 09:14:36

标签: c# asp.net-mvc

我一直收到这个错误: 传递到字典中的模型项的类型为'OutsourcedTicketPlatform.UI.ViewModels.Home.AccountSearchViewModel',但此字典需要类型为'OutsourcedTicketPlatform.UI.ViewModels.Home.AccountDetailsViewModel'的模型项。

家庭控制器:

    public class HomeController : Controller
{
    [Authorize]
    public ActionResult Index()
    {
        return View();
    }

    [Authorize]
    public ActionResult SearchResults(AccountSearchViewModel model)
    {
        if (ModelState.IsValid)
        {
            AccountDetailsViewModel accountDetails = new AccountDetailsViewModel(model.CustomerReferenceNumber);
            return View(accountDetails);
        }

        return View("Index");
    }

    [Authorize]
    public ActionResult MobileResults(AccountDetailsViewModel model)
    {
        if (ModelState.IsValid)
        {
            AccountDetailsViewModel accountDetails = new AccountDetailsViewModel(model.CustomerReferenceNumber);
            return View(accountDetails);
        }

        return View("Index");
    }
}

MobileIssueReporterview:

  @model OutsourcedTicketPlatform.UI.ViewModels.Home.AccountDetailsViewModel



     @{
            ViewBag.Title = "Mobile Issue Reporter";
       }

       <h2>Mobile Issue Reporter</h2>

       <p>Hi (CustomerName) are you phoning today to log the mobile device as lost or                 stolen?</p>


          <p>"Please Confirm your mobile number"</p>

           <p>@Html.TextBox("mobileNumber")</p>

搜索结果视图(导航到移动问题报告者)

   @model OutsourcedTicketPlatform.UI.ViewModels.Home.AccountDetailsViewModel

   @{
          ViewBag.Title = "Key Account Management";
     }

      <fieldset>
       <legend>@ViewBag.Title</legend>

       <p>Please provide the account name:</p>
        @foreach (var item in Model.AccountContacts)
      {
          @Html.RadioButton("AccountContact", item) @item
    }
    <input id="ContactNotListedButton" type="button" value="Contact name not on list" />

        <p>Please provide the first line of the billing address:</p>
         @Html.RadioButton("BillingAddressFirstLine", Model.BillingAddressFirstLine,  false) @Model.BillingAddressFirstLine

  <input id="NoMatchingDetailsButton" type="button" value="No Matching Details" />

  @* 1 = Unicom, 2 = Titan *@
  @if (Model.AccountType == 1 || Model.AccountType == 2)
   {
      <input id="NextButton" type="button" value="Next" />
   }

    @if (Model.AccountType == 1 && Model.IsKeyAccount &&   Model.HasActiveMobileContracts)
   {
      using (Html.BeginForm("MobileResults", "Home", FormMethod.Post))
      {            
        @Html.Hidden("CustomerReferenceNumber","123456")
        @Html.Hidden("customerName", "John Smith")
        @Html.Hidden("mobileNumber", "123456789")
        <input type="submit" value="Mobile Lost or Stolen?" />
       }
   }
   </fieldset>

点击手机丢失或被盗后发生错误?按钮

1 个答案:

答案 0 :(得分:0)

看起来您正在使用模型 AccountSearchViewModel 传递填充值,但该视图需要来自 AccountDetailsViewModel 的数据,并且使用AccountDetailsViewModel模型它可以正常工作。