我一直在寻找,但我找不到如何从该类型转换
Expression<Func<T, DateTime>>
Run Code Online (Sandbox Code Playgroud)
到类型:
Expression<Func<T, object>>
Run Code Online (Sandbox Code Playgroud)
所以我必须再次转向SO的广博知识;)
我想在asp.net mvc应用程序中的不同步骤中构造一个对象,每一步都是一个不同的页面.您在快速Web.Forms应用程序中存储在Session中的那种东西.
阅读它,Session在我看来并不像asp.net MVC的那样.但是我无法真正想到这种情况的其他替代方案,因为TempData和ViewData似乎也不合适,所以也许我错了.
当然,我可以将4个步骤放在一个页面中并显示/隐藏,但这不是我对问题的看法.我想听听你对MVC中Session的看法,如果它对于这种多步骤问题是一个很好的方法,或者你倾向于以其他方式做到这一点.
这非常类似于ASP.NET MVC中的Session变量问题,除了我不是在寻找如何访问Session,但是如果它是解决这个问题的最好方法,或者在Asp中有更好的东西.净MVC.
提前致谢
我使用Visual Studio 2008创建了一个Web服务代理,它为我创建了app.config中的以下条目:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MyNameHandlerSoapBinding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://www.***/***/***"
binding="basicHttpBinding" bindingConfiguration="MyNameHandlerSoapBinding"
contract="***.MyNameHandler" name="MyName">
</endpoint>
</client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
webservice有用户名/密码验证,所以我需要在这里添加它.
我在WCF文档的海洋中有点迷失,我想我必须从basicHttpBinding更改为wsHttpBinding或customBinding才能添加身份验证元素,但我真的不明白它.任何人都可以提供任何快速提示或任何有用的链接,说明如何做到这一点?
编辑:
我将安全部分更改为:
<security mode="Transport">
<transport clientCredentialType="Basic" proxyCredentialType="None"
realm="" />
</security>
Run Code Online (Sandbox Code Playgroud)
并在代码中添加:
ws.ClientCredentials.UserName.UserName = "";
ws.ClientCredentials.UserName.Password = "";
Run Code Online (Sandbox Code Playgroud)
现在它似乎可能正在使用凭据,但它给了我错误:
提供的URI方案'http'是无效的URI预期'https'
我甚至都不知道这是不是正确的方法......
我需要做这样的事情:
<input type="button" value="click" id="mybtn"
onclick="myfunction('/myController/myAction',
'myfuncionOnOK('/myController2/myAction2',
'myParameter2');',
'myfuncionOnCancel('/myController3/myAction3',
'myParameter3');');" />
Run Code Online (Sandbox Code Playgroud)
这个问题的上下文是在onClick上我需要调用一个javascript函数,它将对我提供的url进行ajax调用.它将使用OK和Cancel按钮打开一个模态div.
到目前为止一切都很好.但是我还需要告诉javascript函数另一个函数与其他参数和在新div中单击OK按钮时要调用的url.另一个用于取消按钮.
问题是我无法正确传递第二个参数,因为它没有正确转义并给我javascript错误.
我已经在SO中搜索了其他类似的Javascript问题,但它们似乎没有涵盖我需要做的事情.
有人知道如何将这种字符串参数传递给javascript函数?或许还有另一个更好的解决方案,传递我没想到的东西.
提前致谢
我只是试图从jQuery中的事件中解除一个onclick处理程序,所以我可以稍后将它绑定到另一个函数.
我已经在测试页面中隔离了代码,所以除了肉之外什么都没有,只是一个调用函数的按钮和一个试图解除它的脚本:
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<script src="../../Scripts/jquery-1.3.2.min.js" type="text/javascript">
</script>
<script src="../../Scripts/jquery-1.3.2.js" type="text/javascript">
</script>
<script type="text/javascript" language="javascript">
$(document).ready(function() { $("#btnNext").unbind('click'); });
function hi() {window.alert("hi");}
</script>
</head>
<body>
<input id="btnNext" type="button" value="Next" onclick="hi();" />
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
任何人都知道为什么click事件会一直调用hi()函数,无论我在document.ready中说过什么?
谢谢
从输入文本我需要调用一个函数来捕获onkeydown事件,我需要将一个参数传递给该事件,例如:
<input type="text" onkeydown="TextOnKeyDown('myPrefix');" />...
Run Code Online (Sandbox Code Playgroud)
然后在该功能中我需要知道按下了什么键.我用
function TextOnKeyDown(prefix) {
var key = event.keyCode;
...
}
Run Code Online (Sandbox Code Playgroud)
这就像IE中的魅力一样,但在Firefox中则不然.我已经读过,对于firefox,你必须将一个参数传递给处理程序然后用它来获取密钥,类似于:
<input type="text" onkeydown="detectKey(event)"/>
...
function detectKey(e){
var key = (document.all) ? e.keyCode : e.which;
...
}
Run Code Online (Sandbox Code Playgroud)
但我无法传递我的参数和firefox所需的事件参数.有什么建议?
我正在尝试向泛型方法添加约束,以便检查ValueTypes,Strings或Nullable值类型.
问题是:
那么有人知道我是否可以接受这些并且只能在通用约束中接受这些类型?
问题是我试图接受一个Expression<Func<T, S>参数来表示给定对象的这些类型的属性.
功能将类似于以下(注意代码没有任何意义,只是快速了解我正在寻找的东西):
public class Person
{
public string Name {get; set;}
public DateTime? DOB {get; set;}
public int NumberOfChildren {get; set;}
public Car CurrentCar {get; set;}
}
---
internal void MyGenericMethod<T, S>(T myObject, Expression<Func<T, S> property){...}
Person myPerson = new Person();
MyGenericMethod(myPerson, p => p.Name); //S would be a string
MyGenericMethod(myPerson, p => p.DOB); //S would be a DateTime?
MyGenericMethod(myPerson, p => p.NumberOfChildren); //S would be a struct
Run Code Online (Sandbox Code Playgroud)
上述三个呼叫都应该被接受,但不是以下内容:
MyGenericMethod(myPerson, …Run Code Online (Sandbox Code Playgroud) 我有一个javascript函数调用泛型函数来对服务器进行ajax调用.我需要从ajax调用的回调函数中检索结果(true/false),但我得到的结果总是"未定义".
没有我所有逻辑的通用函数的超简化版本将是:
function CallServer(urlController) {
$.ajax({
type: "POST",
url: urlController,
async: false,
data: $("form").serialize(),
success:
function(result) {
if (someLogic)
return true;
else
return false;
},
error:
function(errorThrown) {
return false;
}
});
}
Run Code Online (Sandbox Code Playgroud)
调用它的函数将是这样的:
function Next() {
var result = CallServer("/Signum/TrySave");
if (result == true) {
document.forms[0].submit();
}
}
Run Code Online (Sandbox Code Playgroud)
"result"变量总是"未定义",调试它我可以看到正在执行回调函数的"return true"行.
有关为什么会发生这种情况的任何想法?我怎样才能将返回值从回调函数冒泡到CallServer函数?
谢谢
为什么这会编译:
public Dictionary<ValueLineType,
Func<HtmlHelper,
string,
object,
Type,
string>> constructor =
new Dictionary<ValueLineType,
Func<HtmlHelper,
string,
object,
Type,
string>>();
Run Code Online (Sandbox Code Playgroud)
但是在Func(布尔值)中有一个额外参数的另一个没有:
public Dictionary<ValueLineType,
Func<HtmlHelper,
string,
object,
Type,
bool,
string>> constructor =
new Dictionary<ValueLineType,
Func<HtmlHelper,
string,
object,
Type,
bool,
string>>();
Run Code Online (Sandbox Code Playgroud)
要么我失明了,要么我今天要学习别的东西:D
c# ×3
javascript ×3
lambda ×3
jquery ×2
ajax ×1
asp.net-mvc ×1
constraints ×1
dictionary ×1
firefox ×1
generics ×1
html ×1
wcf ×1
wcf-security ×1