2015-04-17 45 views
0

我的解决方案中有两个项目。我的一个项目是我想用作模型的类库,而另一个是mvc 4 Web应用程序项目。现在,当我从我的控制器发送我的模型到我的部分视图时,我的视图不呈现,并给出它找不到该类的错误,并且包含该类的程序集丢失,但是我已将我的类库的程序集引用添加到mvc项目。查看无法找到另一个项目中的模型类

我需要问,在MVC项目中是否有必要在同一个项目中使用模型?还是我做错了什么

@using TransactionManagment.Entities; 


@{ 
    ViewBag.Title = "D&C | User Admin"; 
    Layout = "~/Views/Shared/MasterPageLTE.cshtml"; 
} 



@{ 
    var usr = (AppUser)ViewBag.User; 
    var usrRights = usr.AppUserRights.AllUserPossibleRights; 
} 



<style> 
    .mytabs { 
     font-weight: bold; 
     color: cadetblue; 
    } 
</style> 


<script> 
    function IsSuperUser() { 

     if (document.getElementById('chkSuperUser').checked) { 
      document.getElementById('tab_user_rights').style.display = 'none'; 
     } else { 
      document.getElementById('tab_user_rights').style.display = 'inline'; 
     } 
    } 
</script> 


<div class="row"> 
    <div class="col-md-12"> 
     <!-- Custom Tabs --> 
     <div class="nav-tabs-custom"> 
      <ul class="nav nav-tabs"> 
       <li class="mytabs active"><a href="#tab_1" data-toggle="tab" aria-expanded="false">Users</a></li> 
       <li class="mytabs" id="tab_user_rights"><a href="#tab_2" data-toggle="tab" aria-expanded="true">User Rights</a></li> 
      </ul> 
      <div class="tab-content"> 
       <div class="tab-pane active" id="tab_1"> 
        <div class=""> 

         <!-- form start --> 
         <form role="form"> 


          <div class="box-body"> 

           <div class="form-group"> 
            <label>Select</label> 
            <select class="form-control"> 
             <option>New User</option> 
             <option>option 2</option> 
             <option>option 3</option> 
             <option>option 4</option> 
             <option>option 5</option> 
            </select> 
           </div> 
           <div class="form-group"> 
            <label>First Name</label> 
            <input type="text" class="form-control" id="txtFirstName" placeholder="First Name"> 
           </div> 

           <div class="form-group"> 
            <label>Last Name</label> 
            <input type="text" class="form-control" id="txtLastName" placeholder="Last Name"> 
           </div> 

           <div class="form-group"> 
            <label>Designation</label> 
            <input type="text" class="form-control" id="txtDesignation" placeholder="Enter email"> 
           </div> 

           <div class="form-group"> 
            <label>Date of Birth</label> 
            <input type="date" class="form-control" id="txtDateofBirth" placeholder="Date of Birth"> 
           </div> 


           <div class="form-group"> 
            <label>Email address</label> 
            <input type="email" class="form-control" id="txtEmailAdd" placeholder="[email protected]"> 
           </div> 


           <div class="form-group"> 
            <label>Password</label> 
            <input type="password" class="form-control" id="txtPassword" placeholder="Password"> 
           </div> 

           <div class="form-group"> 
            <label>Picture</label> 
            <input type="file" id="txtPicture"> 

           </div> 

           <div class="checkbox"> 
            <label> 
             <input type="checkbox" id="chkSuperUser" onchange="IsSuperUser();"> Super User 
            </label> 
           </div> 
          </div><!-- /.box-body --> 


         </form> 
        </div> 
       </div><!-- /.tab-pane --> 
       <div class="tab-pane" id="tab_2"> 
        @foreach (var upr in usrRights) 
        { 
         foreach (var right in upr.Actions) 
         { 
          <label class=""> 
           <div class="icheckbox_minimal-blue checked" aria-checked="true" aria-disabled="false" style="position: relative;"> 
            <input id="@{'.'+right}" type="checkbox" class="minimal" checked="" style="position: absolute; opacity: 0;"><ins class="iCheck-helper" style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; border: 0px; opacity: 0; background: rgb(255, 255, 255);"></ins> 
           </div> 
          </label> 
         } 

        } 
        <h4>@{usr.UserName}</h4> 
       </div><!-- /.tab-pane --> 

       <div class="box-footer"> 
        <button type="submit" class="btn btn-primary" id="btn_addUser">Save User</button> 
       </div> 
      </div><!-- /.tab-content --> 
     </div><!-- nav-tabs-custom --> 
    </div> 
</div> 

控制器

namespace TransactionManagmentWeb.Controllers 
{ 
    public class UserAdministrationController : Controller 
    { 
     // 
     // GET: /UserAdministration/ 

     public ActionResult UserAdministrationHome() 
     { 
      AppUser user = new AppUser {AppUserRights = new AppUserRights()}; 
      return PartialView(user); 
     } 



    } 
} 

错误

Compilation Error 
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0246: The type or namespace name 'TransactionManagment' could not be found (are you missing a using directive or an assembly reference?) 

Source Error: 


Line 1: 
Line 2: @using TransactionManagment.Entities; 
Line 3: 
Line 4: 
+0

您提供的代码视图? –

+0

和确切的错误? – Oliver

+0

另一个项目中的模型类没有错?对, –

回答

-1

您可能需要在您的视图标记添加

@using theothernamespace.Models 
+1

你可能想避免在答案中猜测,直到你有足够的声望发表评论,所以你可以让OP显示他的视图声明,[我已经做了]( http://stackoverflow.com/questions/29697501/view-can-not-find-model-class-that-is-in-another-project#comment47531441_29697501)。 – CodeCaster

相关问题