2015-04-17 41 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

相關問題