正如标题所说,我想通过JavascriptSerializer将属性标记为不可序列化.怎么能达到这个目的?提前致谢.
我正在使用Moq,我有以下界面:
public interface IGameBoard : IEnumerable<PieceType>
{
...
}
public class GameBoardNodeFactory
{
public virtual GameBoardNode Create (int row, int column, IGameBoard gameBoard)
{
...
}
}
Run Code Online (Sandbox Code Playgroud)
然后我有这样的测试:
var clonedGameBoardMock = new Mock<IGameBoard> (MockBehavior.Loose);
var gameBoardNodeFactoryMock = new Mock<GameBoardNodeFactory> ();
gameBoardNodeFactoryMock.Setup (x =>
x.Create (
position.Row,
position.Column,
clonedGameBoardMock.Object)).Returns (new GameBoardNode { Row = position.Row, Column = position.Column });
Run Code Online (Sandbox Code Playgroud)
但是然后gameBoardNodeFactoryMock.Object.Create(position.Row,position.Column,clonedGameBoardMock.Object)抛出NullReferenceException.我试图为IGameBoard创建一个模拟,这样它就不会扩展IEnumerable <PieceType>接口,然后它就可以了.
任何帮助表示赞赏.
我有一个Web应用程序,它使用Oracle.DataAccess.dll与Oracle数据库进行通信.部署在32位Windows系统上的Web应用程序可以运行,但不能在Windows Server 2008 64位上运行.我安装了10204_vista_win2k8_x64_production_db包,从项目中引用了已安装的dll(版本2.102.4.0),但是我收到以下错误:
无法加载文件或程序集'Oracle.DataAccess,Version = 2.102.4.0,Culture = neutral,PublicKeyToken = 89b483f429c47342'或其依赖项之一.该系统找不到指定的文件.
我在MVC 3应用程序中创建了一个局部视图.此视图具有如下强类型模型:
public class ProductViewModel
{
[Required, Display(Name = "Product price")]
public decimal? ProductPrice
{
get;
set;
} ...
}
Run Code Online (Sandbox Code Playgroud)
在我的动作方法中,我像这样调用PartialView方法
PartialView("ProductViewModel", products[0]);
Run Code Online (Sandbox Code Playgroud)
但是在页面上我看不到验证逻辑的任何标记,如果页面上有任何错误,则没有任何反应.如果我将此局部视图用作编辑器模板,则可以正常工作.任何帮助表示赞赏.
编辑:更具体地说,我有一个HTML表单,我想通过ajax更新添加标记(如果用户点击一个按钮,我想在该表单中添加新标记).如果我静态地包含这些控件,我的意思是如果我在页面加载时渲染它们,验证工作,但如果我通过ajax调用向该表单添加控件,则不会为这些控件插入验证标记.我的局部视图看起来像这样:
@Html.LabelFor(x => x.ProductPrice)
@Html.TextBoxFor(x => x.ProductPrice)
@Html.ValidationMessageFor(x => x.ProductPrice)
Run Code Online (Sandbox Code Playgroud)
我的表单看起来像这样:
@using (Html.BeginForm())
{
<div id="div_Products">
@Html.EditorFor(x => x)
</div>
<input type="submit" value="Compare" />
}
Run Code Online (Sandbox Code Playgroud)
上面的代码效果很好,验证工作正常.在服务器端,我调用一个看起来像这样的动作方法:
[HttpPost]
public ActionResult InsertProduct()
{
var newProductVM = new ProductViewModel{ ProductPrice = 789 };
return PartialView("~/Views/Nutrition/EditorTemplates/ProductViewModel.cshtml", newProductVM);
}
Run Code Online (Sandbox Code Playgroud)
我发现MVC引擎只有在发现控件位于表单控件内时才会插入那些验证标记.当我尝试通过ajax调用更新我的表单控件时,MVC无法知道它们将被放置在表单元素中,这就是为什么它不会为它们发出任何验证逻辑,我想.
validation unobtrusive-javascript data-annotations asp.net-mvc-3
我在项目中使用了以下模板:
<DataTemplate
x:Key="textBoxDataTemplate">
<TextBox
Name="textBox"
ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"
Tag="{Binding}"
PreviewKeyDown="cellValueTextBoxKeyDown">
<TextBox.Text>
<MultiBinding
Converter="{StaticResource intToStringMultiConverter}">
<Binding
Path="CellValue"
Mode="TwoWay">
<Binding.ValidationRules>
<y:MatrixCellValueRule
MaxValue="200" />
</Binding.ValidationRules>
</Binding>
<Binding
RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type y:MatrixGrid}}"
Path="Tag"
Mode="OneWay" />
</MultiBinding>
</TextBox.Text>
</TextBox>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
我使用此模板为用户创建可编辑的矩阵.用户能够在矩阵内从一个单元格导航到另一个单元格,我想突出显示所选文本框中的数据,但它不起作用.我调用TextBox.Focus()和TextBox.SelectAll()来实现效果,但没有.Focus()有效但文本永远不会突出显示.
任何帮助都是受欢迎和赞赏的.
c# ×2
.net ×1
64-bit ×1
asp.net-mvc ×1
datatemplate ×1
ienumerable ×1
mocking ×1
moq ×1
odp.net ×1
oracle ×1
selectall ×1
textbox ×1
validation ×1
windows ×1
wpf-controls ×1