我正试图为Mvc3 RTM运行期货.从webPI安装mvc3后,没有包含.dll.
我已经下载了源代码,并尝试自己构建它,但是当我将它放入我的解决方案并将名称空间添加到Views文件夹下的web.config时,我在每个页面上都会出现以下错误:
S0012: The type 'System.Web.Mvc.Controller' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null'.
Run Code Online (Sandbox Code Playgroud)
我想这是因为强烈的命名或沿着这些方向的东西.
我怎样才能开始运行期货?
编辑:
1)我可能错了,但是从内存来看,当你下载并安装了以前版本的MVC时,它会在Program File/Microsoft ASP.NET/Asp .net MVC2下给你一个Microsoft.Web.Mvc .dll.使用WebPI安装,该位置只有System.Web.Mvc.dll.
2)绝对不是在GAC ......它不是这个组装的地方(我也检查过以确保)
3)不工作的项目是目标项目.我创建了一个新的'Asp .net Mvc 3 Application'来运行它以确保它有效(确实如此).然后我添加了对我从Mvc 3源代码构建的程序集的引用,并更改了"Views"文件夹下的web.config.
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="Microsoft.Web.Mvc" />
</namespaces>
</pages>
Run Code Online (Sandbox Code Playgroud)
4)一旦我删除了命名空间元素和dll,项目就会再次运行.
下面有什么问题
<html>
<body>
<div id='test')28</div>
</body>
</html>
<script>
$(document).ready(function (){
if ($('#test').text().length() > 0) // error here?
alert("test");
});
Run Code Online (Sandbox Code Playgroud)
我在IE 6中得到一个javascript错误,说明在标记错误的行上预期的功能..?
我怎样才能使用Html.TextAreaForwithout编码呢?我知道这是一个安全风险,但我有一个单独的类来消毒任何文本.
例:
@ Html.TextAreaFor(model => model.PostBodyText,10,100,1)
我打算将它与TinyMCE一起使用.
关心RaVen
更新 我正在使用新的Razor View引擎.
布局中是否有一种方法可以确定这是否会呈现内容?
@RenderSection("右",必填:false)
这将确定视图中是否存在实际内容以放置在该部分中.
所以我有一个编辑员工的页面.
这是我的视图模型:
public class EmployeesViewModel
{
[HiddenInput(DisplayValue = false)]
public int EmployeeId { get; set; }
[Required(ErrorMessage = "Position is required")]
[DisplayName("Position")]
public int EmployeeTypeId { get; set; }
[Required(ErrorMessage = "Name is required")]
[DisplayName("Name")]
public string Name { get; set; }
public IEnumerable<EmployeeType> EmployeeTypes { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
public class EmployeesController : Controller
{
public ActionResult Edit(int id)
{
//get employee from id
var employee = GetEmployee(id);
if (employee != null)
{
var viewModel = new EmployeesViewModel …Run Code Online (Sandbox Code Playgroud) 我在asp.net mvc视图上有几个隐藏的输入.它们的值包含类型的对象double.我希望它们能够被渲染,InvariantCulture因为它们习惯于被提供给客户端上的api(谷歌地图).就像现在一样,它们以逗号(,)作为小数分隔符进行渲染,而api则希望将点(.)作为小数分隔符.
最好的解决方案是,如果我可以DisplayFormat在模型的属性上的数据注释属性中指定文化,但我认为这不可能:
public class Position
{
[DisplayFormat(DataFormatString="{0:G}, CultureInfo.InvariantCulture")]
public double Latitude;
...
}
Run Code Online (Sandbox Code Playgroud)
我也不能在我的方法中设置CurrentCultureto ,因为屏幕上还有其他值必须在适当的用户文化中.InvariantCultureApplication_Start
那么,有没有办法暂时改变当前的文化,就在我Html.HiddenFor(Model => Model.Latitude)为特定属性做一个之前,然后重置它?
或者还有另一种更好的方法吗?什么是最佳做法?
我的模型中有一个列表EmployeeList
在我的视图中,我想从EmployeeList(来自Model)填充数组,并将其用作标记的自动完成.似乎数组不是从列表中弹出,也不是自动完成工作.请帮忙.
View中的代码如下:
<title>jQuery Autocomplete example</title>
<script type="text/javascript" src="../../scripts/jquery-1.2.6.js"></script>
<script type="text/javascript" src="../../scripts/jquery.autocomplete.js"></script>
<!-- Listing 14.3 -->
<script type="text/javascript">
$(document).ready(function() {
var employeeList = '@Model.EmployeeLis.toArray();'
$("#tags").autocomplete({
source: employeeList
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
<h1>Type your name here</h1>
<%= Html.TextBox("tags") %>
Run Code Online (Sandbox Code Playgroud)
使用MVC3,我有一个Student Repository(在一个项目中)和一个StudentService(在另一个项目中).在服务中,我想创建一个函数,返回db表中的所有学生.这是一种为我做事的新方式,所以我有点新鲜.在下面的GetAllStudents函数中,我如何更改语法以选择所有.
在存储库中:
namespace SpeakOut.Data
{
public class StudentRepository
{
SpeakOutDataContext context;
private Table<StudentEntity> table;
public StudentRepository()
{
context = new SpeakOutDataContext();
table = context.GetTable<StudentEntity>();
}
public IQueryable<Student> Select()
{
return table.Select(x => new Student
{
WNumber = x.WNumber,
CatalogueYear = x.CatalogueYear,
Standing = x.Standing
});
}
}
Run Code Online (Sandbox Code Playgroud)
}
在服务中:
namespace SpeakOut.Services
{
public class StudentService
{
private StudentRepository repository;
public StudentService()
{
repository = new StudentRepository();
}
public IQueryable<Student> GetAllStudents()
{
return repository.Select().All(x => x.FirstName) ; //**This line is …Run Code Online (Sandbox Code Playgroud) 我有数据,他们在一些页面上被剪切(每页10个结果).
控制器中的代码:
@messages = Message.order('id DESC').page params[:page]
Run Code Online (Sandbox Code Playgroud)
如果需要,我如何在一个页面上显示所有结果?它与'see all'页面导航类似.
在ServiceStack中设置将为特定服务执行的请求/响应拦截器的最简单方法是什么?
请求过滤器(IHasRequestFilter)工作正常,但IHasResponseFilter如果服务返回非2xx状态代码,则不会触发响应过滤器().我需要检索方法返回的状态代码以及响应DTO(如果有的话).
一个自定义的ServiceRunner和覆盖OnBeforeExecute和OnAfterExecute方法似乎工作正常,但我发现它非常具有侵入性,因为需要为整个应用程序替换服务运行器,我找不到一种方法来清除每个功能需要的任务.在那些方法中执行.
ServiceStack中是否有一些我遗漏的扩展点允许我在每个服务方法之前和每个服务方法之后执行一些代码?一个插件是理想的,但我如何订阅一些虚构BeforeExecute和AfterExecute方法,允许我运行一些自定义代码?
更新:
在发布问题后,我发现无论服务返回什么状态代码,都会执行全局响应过滤器,这正是我所需要的.最后一个问题:是否可以检索将在请求过滤器中处理请求的服务类型?我需要检查此服务是否由某个自定义标记属性修饰.
asp.net-mvc ×5
c# ×3
jquery ×2
razor ×2
asp.net ×1
culture ×1
encoding ×1
formatting ×1
html ×1
kaminari ×1
navigation ×1
render ×1
ruby ×1
servicestack ×1