我的解决方案中有两个项目。我的一个项目是我想用作模型的类库,而另一个是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="useremail@domain.com">
</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 :(得分:-1)
您可能需要在视图标记中添加
@using theothernamespace.Models