我刚刚安装了MVC 4 Beta,现在我的MVC 3应用程序无法编译,出现以下错误:
类型'System.Web.Mvc.ModelClientValidationRule'存在于'c:\ Program Files(x86)\ Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll'和'c:\程序文件(x86)\ Microsoft ASP.NET\ASP.NET网页\ v2.0\Assemblies\System.Web.WebPages.dll'C:\ Users\michaeljo\Documents\src\patientgive\Phc.Mvc\Infrastructure\PasswordStrengthAttribute.cs
看起来这已被移动到不同的程序集,因为两个程序集都在GAC中,所以它不知道使用哪个程序集.
我发现这很容易设置; 要么设置配置中缺少一步,它没有正常工作,或者我实际上并不理解它的用途.这里肯定有一些错误.问题显然必须是我.我只是没有让这个工作.这就是我所做的.
创建一个全新的mvc应用程序.在About.aspx页面上放置以下内容.
<%throw new Exception("blah"); %>将内容放在此处.
点击页面获取黄色屏幕异常.
将elmah.dll添加到bin目录.
添加到Web.config文件configurationSections:
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>
Run Code Online (Sandbox Code Playgroud)
将以下内容添加到httpHandlers部分:
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
Run Code Online (Sandbox Code Playgroud)
添加到模块部分:
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
Run Code Online (Sandbox Code Playgroud)
添加到处理程序部分:
<add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" preCondition="integratedMode" type="Elmah.ErrorLogPageFactory, Elmah"/>
Run Code Online (Sandbox Code Playgroud)
添加一个elmah部分:
<elmah>
<errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data" />
</elmah>
Run Code Online (Sandbox Code Playgroud)
这里很奇怪的是,该字符串的".XmlFileErrorLog"部分显示为红色,因为ReSharper错误表明它"无法解析符号'.'''当我在Reflector中查看elmah.dll时显示此对象需要两个公共构造函数中的任何一个中的"字符串"或"IDicationary".
我正在使用VS 2008运行Windows Vista x64.将App_Data的权限设置为Everyone作为Co_Owner.
该HTTP://本地主机:XXXX/elmah.axd页面不上来,并显示没有错误.当我再次点击"关于"页面时,我仍然看到黄色屏幕,elmah.axd仍然显示app_data文件夹没有错误.
我替换了customerrors并创建了相关的页面:
<customErrors mode="On" defaultRedirect="GenericErrorPage.htm" />
Run Code Online (Sandbox Code Playgroud)
自定义页面显示,但elmah.axd仍显示"无错误".App_data仍然是空的!
作为启动此设置的来源,我使用了:code.google.com/p/elmah/wiki/MVC …
我想知道如何从PowerShell以与Visual Studio相同的方式发布.
例如,当您使用MVC项目启动Visual Studio时; 然后右键单击项目并选择"发布"; 出现一个对话框,您可以在再次单击"发布"中填写一些设置.它按预期神奇地推动您的网站.它还会创建一个文件来保存这些设置.projectName.Publish.xml.
该文件是我希望能够以完全相同的方式使用它的原因.有一些设置可以在powershell中进行操作,将应用程序推送到具有不同配置的多个站点.
我查看了"msbuild target:publish",它只生成(从包含.csproj的目录运行):
MSBUILD : error MSB1009: Project file does not exist.
Switch: target:publish
Run Code Online (Sandbox Code Playgroud)
我试过"msbuild projectfile target:publish",它产生:
MSBUILD : error MSB1008: Only one project can be specified.
Switch: target:build
Run Code Online (Sandbox Code Playgroud)
我还看了几个msdeploy变种.这不可能这么难!?如果您可以在工作室中右键单击,则可以执行该任务.
我开始怀疑这是否需要满月并将鸡头切掉.(我花了很多时间在这上面!)
**编辑:我试过李的建议:
msbuild target:publish Mvc.csproj
Run Code Online (Sandbox Code Playgroud)
哪会产生这个错误:
MSBUILD : error MSB1008: Only one project can be specified.
Switch: Mvc.csproj
For switch syntax, type "MSBuild /help"
Run Code Online (Sandbox Code Playgroud)
**编辑:根据DaveE的建议,我试过:
msbuild target:publish Mvc.csproj
Run Code Online (Sandbox Code Playgroud)
哪会产生这个错误:
MSBUILD : error MSB1009: Project file does not exist.
Switch: target:publish=PassportHealth.PatientSimple.Mvc.csproj
Run Code Online (Sandbox Code Playgroud)
我还回到了"发布"目标(http://msdn.microsoft.com/en-us/library/ms165431.aspx)的文档,这似乎很清楚,语法是:
msbuild …
Run Code Online (Sandbox Code Playgroud) msbuild powershell visual-studio-2010 msdeploy visual-studio
我有一个ActionFilter,在OnActionExecuted方法上有一个覆盖.在POST操作中,filterContext.Controller.ViewData.Model始终为null.我确实发现下面的文章似乎说它不应该是null但是这肯定是MVC的早期版本.这是MVC3.我该怎么办?
更新:
我已经找到了原始问题的答案.我有一个自定义ActionResult,它使用自定义日期格式化程序输出JSON.问题是模型没有在控制器中设置.
在我的自定义ActionResult中,ExecuteResult方法传递了ControllerContext,如果我可以在那里设置模型那将是很好的:
context.Controller.ViewData.Model = _data;
Run Code Online (Sandbox Code Playgroud)
但这是在循环的后期,结果在ActionFilter中仍为null.这似乎意味着我需要在控制器中手动设置模型:
ControllerContext.Controller.ViewData.Model = model;
Run Code Online (Sandbox Code Playgroud)
要么
View(model);
Run Code Online (Sandbox Code Playgroud)
这意味着我每次使用这个自定义ActionResult时都需要记住这样做.有更优雅的方式吗?
再来一次更新:
我找到了一种方法来做到这一点它并不像我希望的那样优雅.
在我的comstom ActionResult的构造函数中,我在控制器中发送,至少它始终是一致的:
public JsonNetResult(object data, Controller controller) {
SerializerSettings = new JsonSerializerSettings();
_data = data;
controller.ControllerContext.Controller.ViewData.Model = _data;
}
Run Code Online (Sandbox Code Playgroud) 可以说我有一些接口:
public interface IFoo {
IBar DoesStuff();
}
public interface IBar {
string Thingo { get; }
}
Run Code Online (Sandbox Code Playgroud)
我在整个代码库中使用此代码.需要将IFoo进程移动到不同的系统上(x64与x32的差异),这是我们使用WFC的原因.我的WCF服务实现了此接口.当我创建"服务引用"时,会创建代理存根,但会更改接口.
public interface IFoo {
object DoesStuff();
}
Run Code Online (Sandbox Code Playgroud)
我尝试将IBar/Bar定义为DataService和DataContract,没有区别.有没有办法使用我的界面生成代理代码?
我在想,如果模拟对象可以生成我的界面对象进行测试,那么我是否应该能够获得服务来尊重它?或者做了一些愚蠢和错误的事情?
我已经看过关于这个主题的其他帖子,并且已经摆弄了变化,但仍然无法让JSON模型绑定正常工作.
我在global.asax.cs Application_Start方法中有以下内容:
ValueProviderFactories.Factories.Add(new JsonValueProviderFactory());
Run Code Online (Sandbox Code Playgroud)
回发后的数据如下所示:
{"UserName":"Mike","Password":"password","Persist":true}
Run Code Online (Sandbox Code Playgroud)
我的PoCo:
public class UserLoginViewModel {
public string UserName { get; set; }
public string Password { get; set; }
public bool Persist { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
控制器方法正确触发,但具有UserName = null,Password = null和Persist = false的默认UserLoginViewModel对象; 签名看起来像这样:
[HttpPost]
public ActionResult Logon(UserLoginViewModel model) {
if (ModelState.IsValid) {
...
Run Code Online (Sandbox Code Playgroud) 我有一个配置对象,我存储在数据库中.当应用程序启动时,我想从数据库重新构建对象,然后让Ninject控制它的生命周期.例如"InSingletonScope",当另一个对象请求此对象时,它将来自Ninject内核.
就像是:
Bind(myInstance).ToSelf().InSingletonScope();
Run Code Online (Sandbox Code Playgroud) 被测代码:
module lib {
export class Topic {
private _callbacks: JQueryCallback;
public id: string;
public publish: any;
public subscribe: any;
public unsubscribe: any;
public test: any;
constructor(id: string) {
this.id = id;
this._callbacks = jQuery.Callbacks();
this.publish = this._callbacks.fire;
this.subscribe = this._callbacks.add;
this.unsubscribe = this._callbacks.remove;
}
}
export class Bus {
private static _topics: Object = {};
static topic(id: string): Topic {
var topic = id && this._topics[id];
if (!topic) {
topic = new Topic(id);
if (id) {
this._topics[id] = topic; …
Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×2
controller ×1
elmah ×1
jasmine ×1
json ×1
model ×1
msbuild ×1
msdeploy ×1
ninject ×1
null ×1
powershell ×1
spy ×1
typescript ×1
wcf ×1
wcf-client ×1