我有这样的模型:
public PurchaseOrder
{
[Required] [StringLength(15)]
public virtual string OrderNumber {get;set;}
// etc.
}
Run Code Online (Sandbox Code Playgroud)
当我从视图中提交订单时(使用$ .post,而不是输入type = submit),它会转到我的控制器类:
public class PurchaseOrderController
{
public JsonResult Save(PurchaseOrder order)
{
// TryUpdateModel(order); // commented out since modelstate.isvalid remains false anyway
if (ModelState.IsValid)
{
// its never valid
}
}
}
Run Code Online (Sandbox Code Playgroud)
ModelState.IsValid始终返回false,并返回错误:"订单号字段是必需的." 但是这个领域有一个价值(??为什么)
当它确实有价值时,为什么会说"价值是必需的"?我错过了什么吗?是因为$ .post而不是提交?我能做什么?
这是调试器的样子:
alt text http://www.freeimagehosting.net/uploads/f734f3d95d.png
编辑:额外信息....
我真的认为由于某种原因,模型绑定没有发生.当我尝试这里找到的代码:)
if (!ModelState.IsValid)
{
ModelState.Clear();
ModelMetadata modelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => order, order.GetType());
ModelValidator compositeValidator = ModelValidator.GetModelValidator(modelMetadata, base.ControllerContext);
foreach (ModelValidationResult result in compositeValidator.Validate(null))
{
this.ModelState.AddModelError(result.MemberName, …
Run Code Online (Sandbox Code Playgroud) 是否有可能更改Tortoise SVN的上下文菜单,以便我使用的一些命令更频繁地出现在菜单中的一个级别?
例如,右键单击资源管理器中的文件夹,您会看到这些选项
SVN Update
SVN Commit
Tortoise SVN ... (submenu)
Run Code Online (Sandbox Code Playgroud)
我希望能够将子菜单中的一些项目移动或复制到与更新提交相同的级别,例如
SVN Update
SVN Commit
Repo-browser
Show Log
Tortoise SVN ... (submenu)
Run Code Online (Sandbox Code Playgroud)
对于我一直使用的命令,我已经厌倦了每次扩展子菜单
这是一个与C#MVC2 Jqgrid相关的问题- 进行服务器端分页的正确方法是什么?我在哪里询问并找到了如何在2000行左右的表上提高查询性能.性能从10秒提高到1秒.
现在我正在尝试执行完全相同的查询,其中表有20,000行 - 查询需要30秒.我该如何进一步改进?2万行仍然不是一个巨大的数字.
我有一些可能的想法是:
这是2万行需要30秒的MVC操作:(参数由jqgrid提供,其中sidx =哪个排序列,sord =排序顺序)
public ActionResult GetProductList(int page, int rows, string sidx, string sord,
string searchOper, string searchField, string searchString)
{
if (sidx == "Id") { sidx = "ProductCode"; }
var pagedData = _productService.GetPaged(sidx, sord, page, rows);
var model = (from p in pagedData.Page<Product>()
select new
{
p.Id, p.ProductCode, p.ProductDescription,
Barcode = p.Barcode ?? string.Empty,
UnitOfMeasure = p.UnitOfMeasure != null …
Run Code Online (Sandbox Code Playgroud) 我在使用Web部署部署到默认网站时遇到问题.问题与此类似:MSDeploy批处理文件不再处理引号,其中Web部署在具有空格的部署路径上阻塞.
解决问题的最简单方法是将默认网站重命名为其他没有空格的内容.重命名默认网站是否安全?它会引起任何副作用吗?
在IIS 7.5中,我将cacheControlMaxAge设置为一年
<location path="Content/Images">
<system.webServer>
<staticContent>
<clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
</staticContent>
</system.webServer>
</location>
Run Code Online (Sandbox Code Playgroud)
根据本指南:设置Expires和Cache-Control:ASP.NET中静态资源的max-age标头
但是,Google PageSpeed工具仍然说文件没有缓存:
The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources:
* https://local.example.com/Content/Images/image1.png (expiration not specified)
(etc)
Run Code Online (Sandbox Code Playgroud)
为什么说"未指定过期"?
整个webapp都通过https提供,这是一个因素吗?
可能重复:
使用PHP curl如何获得400响应的响应主体
当使用PHP的curl_exec调用RESTful API时,文档说http://php.net/manual/en/function.curl-exec.php
成功时返回TRUE,失败时返回FALSE.但是,如果设置了CURLOPT_RETURNTRANSFER选项,它将在成功时返回结果,在失败时返回FALSE.
当curl_exec失败时,它返回false.但是,远程服务器可能已尝试返回有用的消息以使用该错误.当它只返回false时,如何使用curl_exec访问此消息?
例如,远程API可能会返回此消息和HTTP 400状态代码:
{"Items":[{"Field":"FirstName","Description":"FirstName is required and cannot be null."}]}
Run Code Online (Sandbox Code Playgroud)
目前我无法读取已返回的此错误消息,而是我得到的所有内容都是false.我也看过curl_info.我确实有返回传输.
在C#中我会使用该exception.Response.GetResponseStream
方法并编写:
private static string Post(WebClient client, string uri, string postData)
{
string response = string.Empty;
try
{
response = client.UploadString(uri, "POST", postData);
}
catch (WebException ex)
{
var stream = ex.Response.GetResponseStream(); // here
if (stream != null)
{
using (var reader = new StreamReader(stream))
{
response = reader.ReadToEnd();
}
}
}
return response;
}
Run Code Online (Sandbox Code Playgroud)
如何在PHP中完成?curl_exec是正确的方法还是应该使用别的东西?
我正在使用每个租户模型一个数据库编写多租户应用程序.我允许每个用户帐户访问多个租户(只要该租户已授予他们访问权限)
发送到浏览器的每个页面都包含Site.Master中的当前TenantId
<%= Html.Hidden("TenantId") %>
Run Code Online (Sandbox Code Playgroud)
但是当从浏览器发出任何请求(提交按钮,AJAX GET或AJAX POST)时,实际上不会检查此TenantId是否与用户当前的TenantId匹配.
现在,如果用户打开一个选项卡,TenantId = 1,则连接到另一个选项卡中的另一个租户,TenantId = 2,然后切换回第一个选项卡,它可以访问租户2中的数据.
我该怎么做才能解决这个问题?我有大量现有的ActionResult和JsonResult方法,我不想通过它们中的每一个并添加
if (request.TenantId != user.CurrentTenantId) return false
Run Code Online (Sandbox Code Playgroud)
因为这将是大量的重复工作
我可以将基本控制器更改为始终读取TenantId的值吗?这可能适用于提交的请求(ActionResult),但是AJAX请求呢?
如何检查JsonResult操作中页面的TenantId而不更改每个现有的AJAX方法(其中有很多)?
如果我有一个基类通过构造函数依赖注入服务:是否可以在不使用的情况下声明子类的构造函数: base (params)
?
public MyBaseClass
{
private IServiceA _serviceA;
private IServiceB _serviceB;
private IServiceC _serviceC;
public MyBaseClass(null, null, null)
public MyBaseClass(IServiceA serviceA, IServiceB serviceB, IServiceC serviceC)
{
_serviceA = serviceA;
_serviceB = serviceB;
_serviceC = serviceC;
}
}
Run Code Online (Sandbox Code Playgroud)
并且注入了一些额外依赖项的子类:
public MySubClassA : MyBaseClass
{
private IServiceD _serviceD;
public MySubClassA (null, null, null, null)
public MySubClassA (IServiceA serviceA, IServiceB serviceB,
IServiceC serviceC, IServiceD serviceD)
: base (serviceA, serviceB, serviceC)
{
_serviceD = serviceD;
}
}
Run Code Online (Sandbox Code Playgroud)
这里的问题是我有多个子类,现在只有10个左右,但数量会增加.每次我需要向基类添加另一个依赖项时,我必须遍历每个子类并在那里手动添加依赖项.这个手工工作让我觉得我的设计有问题.
那么是否可以MyBaseClassA
在子类的构造函数中声明构造函数而不需要基类所需的服务?例如,以便构造函数 …
c# dependency-injection subclass inversion-of-control base-class
我有一个actionlink,我需要它来传递包含连字符( - )的参数.无法更改名称约定.我该怎么做呢?
<li>@Html.ActionLink("abc", "abc", "abc", new { area = "",sap-ie="Edge" }, new { id = nav_abc"})</li>
Run Code Online (Sandbox Code Playgroud)
这个给我一个错误"无效的匿名类型声明符",因为它包含连字符.基本上我需要actionlink来生成如下的html.
<a href=".../abc?sap-ie=Edge" id="nav_abc" >abc</a>
Run Code Online (Sandbox Code Playgroud) 给定一些具有多个字段的 JSON 对象,例如
{a: 1, b: true, c: "some string", d: {foo: "bar"}}
Run Code Online (Sandbox Code Playgroud)
您如何选择其中一些字段作为新的 JSON 对象?
我知道您可以选择一个字段:
select data->>'a' from '{a: 1, b: true, c: "some string", d: {foo: "bar"}}' as data
Run Code Online (Sandbox Code Playgroud)
但是如何将多个字段选择到一个新的 JSON 对象中呢?我如何选择 justa
和b
?
select (what?) from '{a: 1, b: true, c: "some string", d: {foo: "bar"}}' as data
Run Code Online (Sandbox Code Playgroud)
结果将是:
{a: 1, b: true}
Run Code Online (Sandbox Code Playgroud)
我正在使用 9.6 和一个普通的 JSON 列
c# ×6
asp.net-mvc ×3
ajax ×1
base-class ×1
caching ×1
curl ×1
html ×1
http-error ×1
httpresponse ×1
https ×1
iis ×1
iis-7 ×1
iis-7.5 ×1
jqgrid ×1
json ×1
jsonresult ×1
linq ×1
multi-tenant ×1
performance ×1
php ×1
postgresql ×1
routevalues ×1
subclass ×1
svn ×1
tortoisesvn ×1