问题列表 - 第18763页

即使我有一个隐式强制转换运算符(在asp mvc app中),也会抛出异常转换异常

我创建了一个mvc模型类,其中一个属性是'MyObject'类型.它还有一个System.ComponentModel.DataAnnotations.StringLength属性.

MyObject作为隐式转换运算符,因此它基本上可以用作字符串:

public static implicit operator string(MyObject o){...}
public static implicit operator MyObject(string sValue){...}
Run Code Online (Sandbox Code Playgroud)

出于某种奇怪的原因,这是一个asp mvc问题吗?我问,因为我知道在大多数情况下隐式转换工作正常,我可以例如将该属性分配给字符串值,它可以正常工作.

编辑-好吧,我知道为什么错误是发生:
这是因为StringLength.IsValid()方法需要一个对象作为参数,所以中投实际上是从对象去字符串,而不是从MyObject的串,所以这可以解释为什么我的隐式强制转换运算符未被调用.但是如何解决这个问题呢?

这一切都正常,直到我在我的模型中的属性上放置System.ComponentModel.DataAnnotations.StringLength属性,然后当视图从提交按钮发出帖子时,我得到了异常:

[InvalidCastException:无法将类型为'StrataSpot.Shared.Models.Email'的对象强制转换为'System.String'.]
System.ComponentModel.DataAnnotations.StringLengthAttribute.IsValid(Object value)+34
System.Web.Mvc.d__1. MoveNext()+56 System.Web.Mvc.DefaultModelBinder.OnPropertyValidated(ControllerContext controllerContext,ModelBindingContext bindingContext,PropertyDescriptor propertyDescriptor,Object value)+203 System.Web.Mvc.DefaultModelBinder.BindProperty(ControllerContext controllerContext,ModelBindingContext bindingContext,PropertyDescriptor propertyDescriptor)+413
System.Web.Mvc.DefaultModelBinder.BindProperties(ControllerContext controllerContext,ModelBindingContext的BindingContext)90
System.Web.Mvc.DefaultModelBinder.BindComplexElementalModel(ControllerContext controllerContext,ModelBindingContext的BindingContext,对象模型)383
System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext,ModelBindingContext bindingContext)+1048
System.Web .Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext,ModelBindingContext bindingContext)+280
System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext,ParameterDescriptor parameterDescriptor)+257
System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext,ActionDescriptor actionDescriptor)+ 109
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext,字符串actionName)314 System.Web.Mvc.Controller.ExecuteCore()105 System.Web.Mvc.ControllerBase.Execute(RequestContext的RequestContext的)39
的System.Web .Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)+7
System.Web.Mvc.<> c__DisplayClass8.b__4()+ 34 System.Web.Mvc.Async.<> c__DisplayClass1.b__0() 21 System.Web.Mvc.Async.<> c__DisplayClass8 1.<BeginSynchronous>b__7(IAsyncResult _) +12 System.Web.Mvc.Async.WrappedAsyncResult1.End()59 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult的asyncResult)44
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndPro cessRequest(IAsyncResult的结果)7
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()8678910 System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔逻辑completedSynchronously)155

asp.net-mvc implicit-cast implicit-conversion asp.net-mvc-2

3
推荐指数
1
解决办法
1968
查看次数

如何唤醒计算机进入睡眠模式?在Vb 2008 expr版中

我正在尝试制作一个闹钟.当计算机处于睡眠模式时,当触发警报时,我希望计算机唤醒并播放警报.可以告诉我如何在2008年的vb中做到这一点.

vb.net sleep wakeup

2
推荐指数
1
解决办法
2719
查看次数

在apache中设置基本Web代理

我希望运行Apache作为Web开发的代理.我正在运行已安装并运行Apache 2.2.8的Mac OS X 10.5.4.

我想将我的JavaScript文件(在我的机器上本地运行)指向:

http://localhost/test.php
Run Code Online (Sandbox Code Playgroud)

这会打到本地apache服务器,然后将该apache实例转发到我真正的远程服务器:

http://www.mysite.com/test.php
Run Code Online (Sandbox Code Playgroud)

我看了几个演练,但它们似乎已经过时了.我想知道是否有最近如何设置它 - 这里的文档:

http://httpd.apache.org/docs/2.0/mod/mod_proxy.html

给出了一个基本的例子,但我不确定应该在哪里添加文本 - 到http.conf?我只是将其添加到那里,然后重新启动服务器?

谢谢

apache proxy

22
推荐指数
1
解决办法
7万
查看次数

有没有办法嵌套对F#活动模式的调用?

有没有办法将调用嵌套到活动模式?

像这样的东西:

type Fnord =
| Foo of int

let (|IsThree|IsNotThree|) x = 
  match x with
  | x when x = 3 -> IsThree
  | _ -> IsNotThree

let q n =
  match n with
  | Foo x ->
    match x with
    | IsThree -> true
    | IsNotThree -> false
  // Is there a more ideomatic way to write the previous
  // 5 lines?  Something like:
//  match n with
//  | IsThree(Foo x) -> true
//  | IsNotThree(Foo x) …
Run Code Online (Sandbox Code Playgroud)

f#

5
推荐指数
1
解决办法
244
查看次数

magic_quotes_gpc()的解毒剂?

我已经看过几十个这样的PHP代码片段:

function DB_Quote($string)
{
    if (get_magic_quotes_gpc() == true)
    {
        $string = stripslashes($string);
    }

    return mysql_real_escape_string($string);
}
Run Code Online (Sandbox Code Playgroud)

如果我打电话DB_Quote("the (\\) character is cool");会怎么样?(谢谢jspcal!)

难道我们不应该只在剥离斜线get_magic_quotes_gpc() == true 价值源于$_GET,$_POST$_COOKIE超全局变量?

php stripslashes magic-quotes-gpc addslashes

1
推荐指数
2
解决办法
1497
查看次数

学习pycURL有哪些好的教程?

我打算用Python构建我自己的FTP客户端以用于学习目的.我打算使用,PycURL但文档似乎缺乏.

学习pycURL有哪些好的教程?

python pycurl

7
推荐指数
2
解决办法
9705
查看次数

Amazon.com如何使用键值数据存储?

我听说亚马逊使用键值数据存储 - 它不使用传统的关系规范化数据库.作为一个只使用传统方法的人,这是如何工作的?你不需要做以下事情吗?

select * from book where book_id = n

或者:

select * from book where author_id = y

如何在没有标准化数据库的情况下构建具有如此多数据和如此多关系的站点/应用程序?

amazon nosql amazon-simpledb

10
推荐指数
2
解决办法
3089
查看次数

单击超链接时阻止触发父容器单击事件

在我的网页上,我有一个文件列表.

每个文件都在它自己的容器div中(div class ="file").容器内部是文件和描述的链接.

我想允许用户单击容器上的任何位置来下载文件.我通过向容器添加click事件并检索子链接的href来完成此操作.

当文件在新窗口中打开时,如果用户实际单击该链接,则该文件将打开两次.

因此,我需要在单击超链接时阻止触发父容器单击事件.这样做的最佳方法是将超链接功能添加到超链接to0并设置event.stopPropagation吗?据推测,这将阻止事件冒泡到集装箱.

谢谢Ben

javascript javascript-events

13
推荐指数
2
解决办法
3万
查看次数

如何减慢浏览器的速度

我试图在不同的浏览器中测试我的应用程序性能(特别是ie6).

我也安装了ie8,ff和Chrome.我正在使用像ietester这样的工具来查看我的应用程序在ie6中的外观.

我试图找到一种方法,如果浏览器相对较慢(保持带宽/网络速度相同),我的应用程序将如何表现.有没有一种工具或方法可以减慢我的浏览器速度(这样页面加载缓慢,js库加载缓慢)?

谢谢你的帮助!!

javascript browser performance

7
推荐指数
0
解决办法
5192
查看次数

如何在Django的每个页面上显示某些内容?

我很好奇处理每个页面或多个页面上出现某些内容的最佳实践方法,而不必手动将数据分配给每个页面,如下所示:

# views.py

def page0(request):
    return render_to_response(
        "core/index.html",
        {
            "locality": getCityForm(request.user),
        },
        context_instance=RequestContext(request)
    )

def page1(request):
    return render_to_response(
        "core/index.html",
        {
            "locality": getCityForm(request.user),
        },
        context_instance=RequestContext(request)
    )
...
def page9(request):
    return render_to_response(
        "core/index.html",
        {
            "locality": getCityForm(request.user),
        },
        context_instance=RequestContext(request)
    )
Run Code Online (Sandbox Code Playgroud)

现在我可以考虑一些方法来做到这一点,包括编写我自己的Context或者一些中间件,当然,locality在每个页面上复制/粘贴这个任务...我只是不确定这样做的最好方法.我很确定它不是最后一个.

python django

3
推荐指数
1
解决办法
1826
查看次数