使用jquery

时间:2017-06-26 21:33:40

标签: javascript c# asp.net-mvc

您好我正在尝试在需要List<>的视图的模式中加载局部视图单击“新建角色”按钮时的模型。 请问我错过了什么?我收到了错误

  

传递到字典中的模型项的类型是' System.Collections.Generic.List`1 [Vidly.Models.AvailableRole]',但是这个字典需要一个&#39类型的模型项; Vidly.ViewModel.RoleMenuViewModel'

模型

public class RoleMenuViewModel
{
    public RoleMenuViewModel()
    {
        //Menus = new List<Menu>();

        MenuIds = new List<string>();
    }
    public List<string> MenuIds { get; set; }
    public MultiSelectList Menus { get; set; }
    public AvailableRole AvailableRoles { get; set; }
    public List<AvailableRole>  RoleMenu { get; set; }
    }

部分视图

@model Vidly.ViewModel.RoleMenuViewModel
@{
 ViewBag.Title = "Edit Role";
}
<legend>Create or Edit a Role</legend>

@using (Html.BeginForm("SaveRole", "Uam"))
{ 
    <div class="form-group">
        @Html.TextBoxFor(m => m.AvailableRoles.Name, new { @class = "form-control", PlaceHolder = "Role Name" })
        @Html.ValidationMessageFor(m=>m.AvailableRoles.Name)
    </div>

主视图

@model List<Vidly.Models.AvailableRole>

@{
ViewBag.Title = "CreateRole";
Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Available Roles</h2>

<div id="addRoleForm">
<button class="btn btn-success pull-right addRole"  type="button" data-
toggle="modal">New Role</button>
</div>

控制器

public ActionResult Index()
    {
        //get all roles in db
        var availableRoles = dbContext.AvailableRoles.OrderBy(a=>a.Name).ToList(); 

        return View("CreateRole", availableRoles);
    }

 public ActionResult CreateRole(int? id)
    {

        if (id == null)
        {

            var menuViewModel = new RoleMenuViewModel
            {
                 Menus = GetMultiselectItems()
            };

            return View("SaveRole", menuViewModel);
        }

的JavaScript

<script type="text/javascript">
$(".addRole").on("click",
            function() {

                bootbox.dialog({
                    title: "Create new role",
                    message: "@Html.Partial("SaveRoles")"

                });
            });

0 个答案:

没有答案