我有这个剃刀模板
<table>
<tr>
<td>@Html.RadioButtonFor(i => i.Value, "1")</td>
<td>@Html.LabelFor(i => i.Value, "true")</td>
</tr>
<tr>
<td>@Html.RadioButtonFor(i => i.Value, "0")</td>
<td>@Html.LabelFor(i => i.Value, "false")</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
这给了我这个HTML
<table>
<tr>
<td><input id="Items_1__Value" name="Items[1].Value" type="radio" value="1" /></td>
<td><label for="Items_1__Value">true</label></td>
</tr>
<tr>
<td><input checked="checked" id="Items_1__Value" name="Items[1].Value" type="radio" value="0" /></td>
<td><label for="Items_1__Value">false</label></td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
所以我有Items_1__Value两次ID - 当然 - 不好,当我点击第二个标签"false"时,在浏览器中不起作用,第一个收音机将被激活.
我知道我可以在RadioButtonFor中添加一个自己的Id并用我的标签来引用它,但这不是很好,是吗?特别是因为我处于一个循环中而且不能只使用带有附加数字的名称"value",这最终会在我的最终HTML标记中出现在多个Dom Ids中.
不应该是一个很好的解决方案吗?
我有这个(简化的)课程:
public class StarBuildParams
{
public int BaseNo { get; set; }
public int Width { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我必须将它的实例转换为这样的查询字符串:
"BaseNo=5&Width=100"
Run Code Online (Sandbox Code Playgroud)
另外,我必须将这样的查询字符串转换回该类的对象中.
我知道这几乎就是一个模型绑定器所做的事情,但是在我的情况下我没有控制器上下文(一些在线程中运行的深埋类).
那么,是否有一种简单的方法可以在没有控制器上下文的情况下转换查询字符串中的对象并返回?
使用模型绑定会很棒,但我不知道如何.
当我用jQuery发送一个int列表时,如下所示:
$.ajax('@Url.Action("Execute")', {
type: 'POST',
data: {
pkList: [1,2,3]
}
});
Run Code Online (Sandbox Code Playgroud)
然后jQuery将转换pkList对象并通过post发送它,如下所示:
pkList[]:1
pkList[]:2
pkList[]:3
Run Code Online (Sandbox Code Playgroud)
如果服务器是PHP但是我使用Asp.NET MVC3并尝试使用默认模型绑定器获取这些值,这将是正常的:
public ActionResult Execute(ICollection<int> pkList)
Run Code Online (Sandbox Code Playgroud)
但是pkList总是为null,似乎默认的模型绑定器不能绑定它.
我该如何正确解决这个问题?
增加 解决方案
我使用Darin Dimitrov的解决方案traditional在jQuery中设置选项:
$.ajax('@Url.Action("Execute")', {
type: 'POST',
traditional: true,
data: {
pkList: [1,2,3]
}
});
Run Code Online (Sandbox Code Playgroud)
现在jQuery不再添加[]参数了,它们是这样发送的:
pkList:1
pkList:2
pkList:3
Run Code Online (Sandbox Code Playgroud)
MVC默认模型绑定器正确获取值.
希望这有助于某人.
OpenLayers Js脚本是否在某个CDN中可用 - 在缩小版本中?
我不想从他们的网站加载它,这将是缓慢而不好.
更改此对象的最佳方法是什么
{
src: 'img.jpg',
title: 'foo'
}
Run Code Online (Sandbox Code Playgroud)
为有效的HTML标记字符串这样
<img src="img.jpg" title="foo" />
Run Code Online (Sandbox Code Playgroud)
解决方案1
使用jQuery这很容易; 但很复杂:
$('<img/>').attr(obj).wrap('<div/>').parent().html();
Run Code Online (Sandbox Code Playgroud)
有更好的想法吗?
有没有办法在Visual Studio 2010中使用自动生成的参数在javascript中插入XML注释片段?
如果我///在这里打字......
function foo(a, b){
Run Code Online (Sandbox Code Playgroud)
......它应该更改为此(取决于参数):
function foo(a, b){
/// <summary>$cursorhere</summary>
/// <param name="a" type="string">Param a</param>
/// <param name="b" type="string">Param b</param>
/// <returns type="function">Return function</returns>
Run Code Online (Sandbox Code Playgroud)
因此,如果我使用C#代码,它将类似于代码段生成.
编辑
为了澄清,我只是想知道是否有一个快捷方式或现有的插件来实现上述功能近似.
我正在使用ExtJS 4并且有一个带有ajax代理和api的Ext.data.Store:
var gridStore = Ext.create('Ext.data.Store', {
autoSync: true,
proxy: {
type: 'ajax',
api: {
read: 'myurl',
create: 'myurl',
update: 'myurl',
destroy: 'myurl'
},
reader: {
type: 'json',
successProperty: 'success',
root: 'data',
messageProperty: 'message'
},
writer: {
type: 'json',
writeAllFields: false,
root: 'data'
},
listeners: {
exception: function(proxy, response, operation){
Ext.MessageBox.show({
title: 'Server error',
msg: operation.getError(),
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
}
...
Run Code Online (Sandbox Code Playgroud)
当我使用更新功能并且我的服务器返回一个json对象时success:false(因为他输错了),我关联网格中的字段仍然标记为已更改,并且用户可以选择更改其错误的值.
这很好.
但是当我从商店中删除记录时......
var store = Ext.StoreManager.lookup('gridStore');
store.remove(store.getById(id));
Run Code Online (Sandbox Code Playgroud)
...然后ExtJS首先从商店中删除此记录,然后调用ajax api.因此当destroy api返回时success:false,消息显示为异常,就像更新api一样,那很好,但我的记录已从商店中删除了!例如,来自服务器的异常表示您无法删除此记录,因为它已经在商店中删除了.
如何在服务器同步后取消存储删除?如果服务器返回,我希望记录留在商店中 …
在Photoshop中,您可以选择"颜色"(从底部开始的第二个)将混合模式设置为下一个较低层:

如果图像顶部只有一个渐变,结果可能如下所示:

我在某处找到的颜色混合模式的描述是:
颜色将下层的色调和饱和度改变为上层的色调和饱和度,但仅留下亮度.
到目前为止我的代码是:
using(var g = Graphics.FromImage(canvas))
{
// draw the lower image
g.DrawImage(lowerImg, left, top);
// creating a gradient and draw on top
using (Brush brush = new LinearGradientBrush(new Rectangle(0, 0, canvasWidth, canvasHeight), Color.Violet, Color.Red, 20))
{
g.FillRectangle(brush, 0, 0, canvasWidth, canvasHeight);
}
}
Run Code Online (Sandbox Code Playgroud)
但那是 - 当然 - 只是在较低的图像上绘画.
所以问题是:
如何使用Photoshop中提供的混合模式"颜色"在另一个图像上绘制图像?
编辑:
为了让我更清楚我想要实现的目标:

如果有人想使用图像进行测试:

我在d3.js中有两个简单的物体,它们应围绕视口的中心盘旋(就像围绕太阳的行星一样).
我是d3.js的新手,我知道我必须使用过渡但是因为行星必须一直循环而不仅仅是进入或退出我不知道在哪里以及如何设置过渡.
这是我目前的代码:
var planets = [
{d:100,r:2},
{d:150,r:4}
];
var w = 500, h = 400, svg, circle;
function init(){
svg = d3.select("#drawArea").append("svg").attr({width: w, height: h});
var center = {
x: Math.floor(w/2),
y: Math.floor(h/2)
};
svg.append('circle').attr({
'cx': center.x,
'cy': center.y,
'r': 10,
'class': 'sun'
});
circle = svg.selectAll(".planet")
.data(planets)
.enter()
.append("circle")
.attr("class", "planet")
.attr("r", function(s){return s.r});
circle.attr({
// distance from the center
'cx': function(s){ return center.x - s.d; },
// center of the screen
'cy': function(s){ return center.y; } …Run Code Online (Sandbox Code Playgroud)