我是新手knockout.js.另外我是asp.net mvc 3的上层中间人.我真的想学习如何在mvc 3剃须刀中使用淘汰赛js?但是下面的代码不起作用也回到我空的总价.没有错误.请帮助谢谢......
模型:
public class GiftModel
{
public string Title { get; set; }
public double Price { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
视图:
@using System.Web.Script.Serialization;
@model IEnumerable<knockout1.Models.GiftModel>
@{
ViewBag.Title = "Index";
}
<script src="/Scripts/knockout-2.1.0.js" type="text/javascript"></script>
<script type="text/javascript">
var initialData = @(new JavaScriptSerializer().Serialize(Model));
var viewModel = {
gifts : ko.observableArray(initialData)
};
ko.applyBindings(viewModel);
</script>
<h2>Index</h2>
<p>You have asked for <span data-bind="text: gifts().length"> </span> gift(s)</p>
Run Code Online (Sandbox Code Playgroud)
控制器:
public class TestController : Controller
{
//
// GET: /Test/
public ActionResult Index()
{
var initialState …Run Code Online (Sandbox Code Playgroud) 点击li项目后.我将active属性设置为css类,但li有一个转发另一个页面的链接.活跃的css消失了吗?这该怎么做?我已经使用localstorage缓存我选择的旧项目.我找不到任何解决方案.如何在刷新后进行活动类设置?刷新页面后如何设置活动类?
<script type="text/javascript">
$(document).ready(function () {
$("li").click(function () {
var id = $(this).attr("id");
console.log(id);
var selectedolditem = localStorage.getItem('selectedolditem');
if (selectedolditem != null) {
$('#' + selectedolditem).siblings().find("active").removeClass("active");
$('#' + selectedolditem).addClass("active");
localStorage.clear();
return;
}
$('#'+id).siblings().find("active").removeClass("active");
$('#' + id).addClass("active");
localStorage.setItem("selectedolditem", id);
});
});
Run Code Online (Sandbox Code Playgroud)
我知道如何将nvarchar转换为十进制(18,4)Cast方法.我的表行数为80000.我的查询在下面运行完美...
SELECT top 80000 id, Cast(MH as decimal(18,4)) as MH
FROM TaskRelations WHERE MH is not null
Run Code Online (Sandbox Code Playgroud)
但;
但下面选择查询不工作!如果写在下面:
SELECT id, Cast(MH as decimal(18,4)) as MH
FROM TaskRelations WHERE MH is not null
Run Code Online (Sandbox Code Playgroud)
错误:将数据类型nvarchar转换为数字时出错.
我不需要通过Activator createInstance使用创建新实例,为什么我需要它呢?我需要在哪些情况下使用Activator.CreateInstance()?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
namespace App.CreateInstance
{
class Program
{
static void Main(string[] args)
{
new MyCustomerManager().Save <MyCustomer>(new object[] {
1,
"xxx",
"yyyy" });
}
}
public class MyCustomerManager
{
public void Save<TModel>(object[] Vals)
{
Type calcType = typeof(TModel);
object instance = Activator.CreateInstance(calcType);
PropertyInfo[] ColumnNames = instance.GetType()
.GetProperties();
for (int i = 0; i < ColumnNames.Length; i++)
{
calcType.GetProperty(ColumnNames[i].Name,
BindingFlags.Instance
| BindingFlags.Public )
.SetValue(instance, Vals[i], null);
}
string result = "";
for …Run Code Online (Sandbox Code Playgroud) 我知道松散耦合和紧密耦合的信息.但我暂停什么时候可以决定在哪里和什么时候使用?我不明白什么时候我需要松散耦合和紧密耦合?
请看:http://www.dofactory.com/Patterns/PatternAdapter.aspx#_self1
如果你看适配器类:
///
/// The 'Adapter' class
///
class Adapter : Target
{
private Adaptee _adaptee = new Adaptee();
public override void Request()
{
// Possibly do some other work
// and then call SpecificRequest
_adaptee.SpecificRequest();
}
}
Run Code Online (Sandbox Code Playgroud)
以上用法就像紧紧耦合!我认为紧密耦合是糟糕的用法.但适配器模式紧密耦合使用.当我需要紧密和松散耦合?
我有一个GridControl:
<dxg:GridControl Name="grd" Height="270">
<dxg:GridControl.Columns>
<dxg:GridColumn Header="Id" FieldName="Id" AllowEditing="True" Width="30"/>
<dxg:GridColumn Header="Name" FieldName="Name" AllowEditing="False" />
<dxg:GridColumn Header="SurName" FieldName="SurName" AllowEditing="False" />
<dxg:GridColumn Header="Age" FieldName="Age" CellStyle="{StaticResource customCellStyle}" AllowEditing="False" />
<dxg:GridColumn Header="Income" FieldName="Income" AllowEditing="False" />
<dxg:GridColumn Header="Dept" FieldName="Dept" AllowEditing="False" />
</dxg:GridControl.Columns>
</dxg:GridControl>
Run Code Online (Sandbox Code Playgroud)
我一直在绑定itemsource = List.但是如果
Age <= 0或Income <0或Dept <= 0(在绑定数据后行着色为红色)我想要着色
我怎样才能做到这一点?
我想使用 AOP 来处理控制台应用程序中的错误异常。(这不是 MVC,我使用属性花瓶编程来处理 MVC 中的错误,但这是控制台应用程序)我的代码如下:(如果发生错误,它应该在我的属性端代码中抛出错误)
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class HandleError : Attribute
{
public HandleError(string description)
{
try
{
this.Description = description;
}
catch (Exception)
{
throw;
}
}
public string Description { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这将从我的方法中调用:
[HandleError("Error occurs here")]
public static void MyMethod(string data)
{
throw new Exception();
Run Code Online (Sandbox Code Playgroud)
实际上; 我想使用 AOP 来处理我的方法内的异常。如果发生错误,我必须调用属性。但如何呢?(请不要提供 postsharp,它需要钱。但我也开放开源)顺便说一句;为什么这不容易,我不明白。
你能解释使用声明的匿名类型吗?你能解释两种用法的利弊吗?
using(var myCtx = new Entity() )
{
}
Run Code Online (Sandbox Code Playgroud)
另一个:
using(Entity myCtx = new Entity() )
{
}
Run Code Online (Sandbox Code Playgroud)
他们之间有什么区别?
我有一个特殊的问题,我真的想学习如何开发自定义的aspx页面; 如果您自动创建一个aspx页面页面:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Test.xyz
{
public partial class MyPage: System.Web.UI.Page
{
}
}
Run Code Online (Sandbox Code Playgroud)
但我想开发:如果新闻创建aspx页面:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyFrameWork.Business;
sing MyFrameWork.DAL;
namespace Test.xyz
{
public partial class MyPage: System.Web.UI.Page
{
}
protected void Save()
{
}
protected void Delete()
{
}
}
Run Code Online (Sandbox Code Playgroud)
如何生成此页面右键单击 - 添加新项目(自动)
我的问题太简单但令人费解.我有一个开发mvc页面来学习.我使用了Repeater服务器控件.
<asp:Repeater ID="ProductList" runat="server">
<ItemTemplate>
<li>
<%#Eval("Name") %>
</li>
</ItemTemplate>
Run Code Online (Sandbox Code Playgroud)
还:(查看)
public partial class ListProduct : ViewPage
{
protected void Page_Load(object sender, EventArgs e)
{
ProductList.DataSource = ViewData["Products"];
ProductList.DataBind();
}
}
Run Code Online (Sandbox Code Playgroud)
我的Repeater Server控件运行良好.但我添加了一个GridView控件.错误返回给我:
<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="id" HeaderText="" Visible="false" />
<asp:BoundField DataField="Name" HeaderText="" Visible="true" />
</Columns>
</asp:GridView>
<asp:Repeater ID="ProductList" runat="server">
<ItemTemplate>
<li>
<%#Eval("Name") %>
</li>
</ItemTemplate>
</asp:Repeater>
</asp:Content>
Run Code Online (Sandbox Code Playgroud)
视图:
GridView1.DataSource = ViewData["Products"];
GridView1.DataBind();
Run Code Online (Sandbox Code Playgroud)
错误**:控件'GridView'类型的'ContentPlaceHolder2_GridView1'必须放在带有runat = server的表单标签内.**
我通过添加表单runat服务器来理解并解决了问题.但我不明白原因?Repeater和GridView是服务器控件.仅在转发器使用中没有错误转发器.GRidView返回错误.为什么?
我有一个模特:
[Range(1, 24, ErrorMessage = "Invalid Hour")]
public int val1{ get; set; }
[Required(AllowEmptyStrings = true)]
public string val2 { get; set; }
Run Code Online (Sandbox Code Playgroud)
我有一个编辑动作,我也有查看页面.val1.text, val2.text如果我写填充视图表单有两个文本框(我没有写任何值val1)返回InvalidHour.我想提供设置空值的能力(不在val1上写东西).val1上的问题返回空时无效小时!我可以空吗?
怎么做?
我有一些代码如下所示.我想这是Singleton模式.为什么我需要一个静态构造函数.这也有什么好处?感谢您的回复 ...
public sealed class Myclass
{
static Myclass()
{
Myclass.Application = new Myclass();
}
protected Myclass()
{
}
static Myclass _application;
public static Myclass Application
{
get { return Myclass._application; }
protected set { Myclass._application = value; }
}
string _name;
public string Name
{
get { return _name}
protected set { _name= value; }
}
}
Run Code Online (Sandbox Code Playgroud) 我想更新test1表格的一些行.ColumnCtest1中为零.
例如:
ColumnA是父节点.ColumnA + ColumnB是主键.
create table test(ColumnA int, ColumnB int, ColumnC int);
Insert Into test Values(1, 10,0);
Insert Into test Values(2, 11,0);
Insert Into test Values(3, 14,0);
create table test1(ColumnA int, ColumnB int, ColumnC int);
Insert Into test1 Values(1, 9,123);
Insert Into test1 Values(1, 10,0);
Insert Into test1 Values(2, 10,128);
Insert Into test1 Values(2, 11,0);
Insert Into test1 Values(3, 13,145);
Insert Into test1 Values(3, 14,0);
Run Code Online (Sandbox Code Playgroud)
我想要的结果:

我不工作的代码:
update test1 a
set a.ColumnC = b.ColumnC
from …Run Code Online (Sandbox Code Playgroud) c# ×9
.net ×4
asp.net ×2
asp.net-mvc ×2
sql ×2
sql-server ×2
t-sql ×2
aop ×1
c#-4.0 ×1
css ×1
data-binding ×1
devexpress ×1
html ×1
html5 ×1
javascript ×1
jquery ×1
knockout.js ×1
mvvm ×1
oop ×1
postsharp ×1
razor ×1
singleton ×1
wpf ×1