我DataAnnotations用于在ASP.NET MVC应用程序中ViewModel使用jquery.validate.unobtrusive和在服务器端验证我的客户端.
不久前,我发现我可以写这样的验证:
[Required(ErrorMessage = "{0} is required")]
public string Name { get; set; }
Run Code Online (Sandbox Code Playgroud)
这样我就可以在配置或资源中轻松定义一些通用字符串,并始终使用它DataAnnotations.因此,将来在整个应用程序中更改验证消息会更容易.
另外我知道有一个FluentValidation库允许向现有的验证规则添加验证规则ViewModel.我知道添加/编辑有一个问题ViewModels,可能有类似的字段,但ValidationRules不同.
客户端验证的另一个问题是,应该解析新添加到DOM的 html (使用ajax请求)以启用验证.我是这样做的:
$('#some-ajax-form').data('validator', null);
$.validator.unobtrusive.parse('#some-ajax-form');
Run Code Online (Sandbox Code Playgroud)
所以我有一些问题:
ViewModel验证问题的最佳方法?我可以使用DataAnnotations与FluentValidation或单独添加和编辑ViewModels仍然是最好的选择?我不是问如何创建自己的DataValidators我知道怎么做.我想方设法如何以更高效和易维护的方式使用它们.
c# validation asp.net-mvc data-annotations unobtrusive-validation
今天我维护的项目非常混乱,需要大量的重构并在客户端机器上发布.
我知道我可以添加一个只包含数据库脚本的SQL Server数据库项目,并创建一个.dacpac允许我自动更改客户端数据库的文件.
此外,我知道我可以只添加一个.mdf文件到App_Data甚至Solution_Data文件夹,有我的数据库存在.我认为localDb已经存在允许我在没有SQL Server的情况下启动我的解决方案
而且我知道实体框架存在于它自己的迁移中.但我不想使用它,besouse我无法添加和更改索引的迁移,当我需要描述困难的迁移场景时,我没有灵活性.
我的目标:
.dbml).那么我要问的是:
如果我想实现目标,使用这两种方法有什么优点和缺点?
可以说我应该使用这种工具的组合吗?
或者我不知道MS的其他现有工具?
有没有办法从这个DB 更新我的DAL模型?
我正在尝试使用Deep Zoom Image(formart)支持实现OpenSeadragon查看器..dzi
为了使事情正常工作,我应该xml在服务器端创建适当的瓷砖.
微软的Deep Zoom Composer的包含DeepZoomTools.dll.它提供了我需要的功能.我把它添加dll到我的项目中.
所以我有一些问题:
dll在服务器端使用它是否有任何法律问题,因为它是SilverLight 3的一部分?DeepZoomTools.dll在这个包中使用吗?我可以在我的Github项目中使用什么样的许可证呢?DeepZoomTools.dll并对其进行一些更改,以便添加一些功能,然后在项目和NuGet包中使用它吗?最后一个问题:为此目的,是否有任何.net替代库?(我知道我们不能在这里询问工作库,但仍然)
你尝试用角度项目asp.net创建一个简单的网络mvc 5我有这个js
var app = angular.module("app", ["ngRoute"])
.config(function ($routeProvider, $locationProvider) {
$routeProvider.when('/', {
templateUrl: '/AngularJS/Templates/inicio.html',
controller: 'bienvenidoController'
});
$locationProvider.html5Mode(true);
});
Run Code Online (Sandbox Code Playgroud)
还有这个:
app.controller("bienvenidoController", function ($scope) {
});
Run Code Online (Sandbox Code Playgroud)
视图:布局:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
</head>
<body ng-app="app">
@RenderBody()
<!--Librerias Angular-->
<script src="~/Scripts/angular.min.js"></script>
<script src="~/Scripts/angular-route.min.js"></script>
<!---Librerias App-->
<script src="~/AngularJS/RegistrationModule.js"></script>
<script src="~/AngularJS/bienvenidoController.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
指数:
<div ng-view>
</div>
Run Code Online (Sandbox Code Playgroud)
和:
<h1>Hola Mundo!</h1>
Run Code Online (Sandbox Code Playgroud)
错误:
错误:[$ location:nobase]
错误见firebug mozilla
我有一个使用Bootstrap的移动网络应用程序.桌面上的一切看起来都很好; 然而,当我在iPhone 4S上拉出某些页面时,导航栏比它应该更窄.具有此行为的两个页面都有表,因此可能与它有关.
截图: 
我共享的_LayoutRazor视图如下所示:
@using FCTech.Quotes.Helpers
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>@ViewBag.Title</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/css")
@Styles.Render("~/Content/themes/base/css")
@Styles.Render("~/Content/bootstrap")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@RenderSection("Styles", false)
</head>
<body>
<header>
<div class="content-wrapper">
<div>
<nav class="navbar navbar-default col-xs-12">
<div class="container-fluid">
<div class="navbar-header float-left">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navLinks" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("Home", "Index", new { controller = "Home" }, …Run Code Online (Sandbox Code Playgroud) 我在 ASP.NET MVC 项目中使用 FluentValidation 库,从 UI 角度来看,它按预期工作。违反规则会显示正确的错误。
我有一个父类,它有一个验证器和一个集合属性,其中该类型有一个验证器。它在概念上与文档中描述的相同。
我有一个父类的验证器......
public class MyFormValidator : AbstractValidator<MyFormViewModel>
Run Code Online (Sandbox Code Playgroud)
...我有一个收藏MyFormViewModel...
public IList<ChildRow> ChildRowsAdded { get; set; }
Run Code Online (Sandbox Code Playgroud)
...我为该子类的集合创建一个验证器...
public class ChildRowValidator : AbstractValidator<ChildRow>
Run Code Online (Sandbox Code Playgroud)
...并且我在父验证器中使用该子验证器...
RuleFor(m => m.ChildRowsAdded).SetCollectionValidator(new ChildRowValidator());
Run Code Online (Sandbox Code Playgroud)
在编写一些单元测试时,我注意到这ShouldHaveValidationErrorFor并不能确认错误的存在。
_validator.ShouldHaveValidationErrorFor(x => x.ChildRowsAdded, model);
Run Code Online (Sandbox Code Playgroud)
我的测试中的那一行似乎没有看到错误。测试失败并显示消息
FluentValidation.TestHelper.ValidationTestException:预计属性 AllergyRowsAdded 出现验证错误。
如果我手动.Validate()查看结果,我会看到错误。
以前有人遇到过这个吗?ShouldHaveValidationErrorFor在这种情况下我需要采取额外的步骤吗?
我的数据库上有3个表.
- -学生 - -
id - 名字
- -语言 - -
id - lang
---学生语言---(普通表)
id - studentId - langId
学生可以拥有更多语言.我想搜索具有int[]数组值的学生.但不是IN()- Contains(),它必须与and- &&运算符和此运算符int[]取值.
在sql =
`select t1.id, t1.name from Student t1 join StudentLanguage t2
ON(t1.id=t2.studentId) where (t2.langId=1 and t2.langId=3 and t2.langId=5);`
Run Code Online (Sandbox Code Playgroud)
那么如何使用Entity Framework进行此查询?(... where new int[] { 1,3,5 })
我有一个C#ASP.Net Razor(非MVC)网页......
@using QuickCodeLearning.Customers.Utilities;
@{
var cus = CustomerUtilities.GetCustomerInformation(1);
}
<html>
<head>
<title>
Display a Customer
</title>
</head>
<body>
<p>@cus.fname @cus.lname @cus.FavFruit</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我通过using语句包含了一个类库(QuickCodeLearning.Customers.Utilities).
一切正常.
我的问题是我可以将这个类库添加到我的Web.Config文件中,这样我就不必在每个页面的顶部都有using语句了吗?
这是我的Web.Config档案......
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="CustomersEntities" connectionString="metadata=res://*/CustomersEF.csdl|res://*/CustomersEF.ssdl|res://*/CustomersEF.msl;provider=System.Data.SqlClient;provider connection string="data source=LT5V6V8W1\SQLSERVERROCKS;initial catalog=sandbox;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<system.web>
<authentication mode ="Windows"/>
<identity impersonate="true"/>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我尝试将<page> <namespace>添加到Web.Config文件中,如下所示...
<?xml version="1.0"?>
<configuration>
<pages>
<namespaces>
<add namespace="QuickCodeLearning.Customers.Utilities" />
</namespaces>
</pages>
<connectionStrings>
<add name="CustomersEntities" connectionString="metadata=res://*/CustomersEF.csdl|res://*/CustomersEF.ssdl|res://*/CustomersEF.msl;provider=System.Data.SqlClient;provider connection string="data source=LT5V6V8W1\SQLSERVERROCKS;initial catalog=sandbox;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings> …Run Code Online (Sandbox Code Playgroud) 我想要小数点后只有 2 位数字。
@Html.TextBoxFor(m => m.Viewers, new { @tabindex = 7 })
Run Code Online (Sandbox Code Playgroud)
需要这样的输出:
56.23
456.20
1.21
像那样..
因此,我们正在考虑在组织中使用多维数据集。
现状:
已知问题:
我们现在如何解决问题:
优点:
角色:
已知替代方案:
问题:
asp.net-mvc ×4
c# ×3
sql ×2
sql-server ×2
.net ×1
angularjs ×1
architecture ×1
css ×1
cube ×1
dacpac ×1
deepzoom ×1
html ×1
ios ×1
licensing ×1
migration ×1
razor ×1
silverlight ×1
validation ×1