我有一个辅助类,它传递一个值数组,然后从我的模型传递给一个新类.如何验证给予此类的所有值是否有效?换句话说,如何在非控制器类中使用ModelState的功能.
从控制器:
public ActionResult PassData()
{
Customer customer = new Customer();
string[] data = Monkey.RetrieveData();
bool isvalid = ModelHelper.CreateCustomer(data, out customer);
}
Run Code Online (Sandbox Code Playgroud)
来自帮手:
public bool CreateCustomer(string[] data)
{
Customter outCustomer = new Customer();
//put the data in the outCustomer var
//??? Check that it's valid
}
Run Code Online (Sandbox Code Playgroud) 我有一个表单发布到MVC的一个动作.我想从操作中的FormCollection中提取所选的下拉列表项.我该怎么做?
我的Html表格:
<% using (Html.BeginForm())
{%>
<select name="Content List">
<% foreach (String name in (ViewData["names"] as IQueryable<String>)) { %>
<option value="<%= name %>"><%= name%></option>
<% } %>
</select>
<p><input type="submit" value="Save" /></p>
<% } %>
Run Code Online (Sandbox Code Playgroud)
我的行动:
[HttpPost]
public ActionResult Index(FormCollection collection)
{
//how do I get the selected drop down list value?
String name = collection.AllKeys.Single();
return RedirectToAction("Details", name);
}
Run Code Online (Sandbox Code Playgroud) 在使用WCF调用Cisco的AXL SOAP API时,我的CPU使用率很高.我首先使用wsdl生成的类创建服务模型clientbase.我正在使用basichttpbinding和transfermode作为缓冲.执行调用时,CPU最大化,并且CPU配置文件显示96%的CPU时间_TransparentProxyStub_CrossContext@0来自在调用之后调用的clr.dll base.Channel.getPhone(request);.更准确地说,该调用最大化了进程正在运行的CPU核心.
这是来自wsdl generate的客户端创建的片段
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class AXLPortClient : System.ServiceModel.ClientBase<AxlNetClient.AXLPort>, AxlNetClient.AXLPort
{
public AXLPortClient()
{
}
public AXLPortClient(string endpointConfigurationName) :
base(endpointConfigurationName)
{
}
...
Run Code Online (Sandbox Code Playgroud)
这就是我创建客户端的方式:
public class AxlClientFactory : IAxlClientFactory
{
private const string AxlEndpointUrlFormat = "https://{0}:8443/axl/";
public AXLPortClient CreateClient(IUcClientSettings settings)
{
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;
ServicePointManager.Expect100Continue = false;
var basicHttpBinding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
basicHttpBinding.MaxReceivedMessageSize = 20000000;
basicHttpBinding.MaxBufferSize = 20000000;
basicHttpBinding.MaxBufferPoolSize = 20000000;
basicHttpBinding.ReaderQuotas.MaxDepth = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用调度计时器测量按键事件之间的经过时间(以毫秒为单位),但是当声明调度计时器的间隔为1毫秒然后建立tick事件时,它不会每隔1毫秒触发一次,而是像10- 100毫秒(猜测).如果此刻度事件未按时触发,如何准确测量时间(以毫秒为单位)?我在Silverlight中这样做,似乎无法访问System.Timers.System.Threading.Timer似乎也发生了同样的情况.
以下是代码的基础知识:
public void StartTimer(object o, RoutedEventArgs sender)
{
System.Windows.Threading.DispatcherTimer myDispatcherTimer = new
System.Windows.Threading.DispatcherTimer();
myDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 1); // 1 Milliseconds
myDispatcherTimer.Tick += new EventHandler(Each_Tick);
myDispatcherTimer.Start();
}
// A variable to count with.
int i = 0;
public void Each_Tick(object o, EventArgs sender)
{
i++;
}
public void keypress(object s, EventArgs args)
{
label1.contents = i.ToString();
i = 0;
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?