我在表单中有一个文本框,我想添加一些验证.
如何在不使用模型的情况下为其添加一些不显眼的验证属性?
例如.
@using (Html.BeginForm())
{
@Html.ValidationSummary()
@Html.Label("code", "Confirmation Code")
@Html.TextBox("code")<!-- I want validation on this thing -->
<input type="submit" value="Go" />
}
Run Code Online (Sandbox Code Playgroud)
我该如何制作它required,以及其他如强度等.
我有这两个型号:
public class SiteSettingsViewModel
{
public decimal SubscriptionFee { get; set; }
}
public class SiteSettings
{
public decimal SubscriptionFee { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
和代码:
var model = Mapper.Map<SiteSettings, SiteSettingsViewModel>(settingService.GetSettings());
Run Code Online (Sandbox Code Playgroud)
这引发了以下错误:
尝试将WebApp1.Domain.Site.SiteSettings映射到WebApp1.WebUI.ViewModel.SiteSettingsViewModel.缺少类型映射配置或不支持的映射.抛出了"AutoMapper.AutoMapperMappingException"类型的异常.
为什么我需要输入代码:
Mapper.CreateMap<SiteSettings, SiteSettingsViewModel>();
Run Code Online (Sandbox Code Playgroud)
对我来说,这似乎是我在编写猴子代码.这不是必需的.
为什么1号线不起作用?
我安装 GitExtensions 的主要目的是在 Visual Studio 2010 中使用 GitHub。当我启动 GitExtensions 时,我的清单中出现 2 个错误,还有一个启动错误,内容为:
Access to path 'c:\program files(x86)\GitExtensions\.gitconfig' is denied.
该目录中没有 .gitconfig 文件。它不允许我设置所需的信息,例如我的姓名和电子邮件。我能做些什么来解决这个问题吗?
当我ListBox使用RIA服务填充时,会自动选择一个项目.这会触发SelectionChanged事件.如果我使用箭头键向上或向下移动选择,则事件也会被触发.
我不想要这个.我希望用户按回车或单击要选择的项目.我该如何做到这一点?
首先,我从未见过使用ninject和wcf的例子.
这是我的.svc:
<%@ ServiceHost Language="C#" Debug="true" Service="MyService.Services.NotifyService" %>
Run Code Online (Sandbox Code Playgroud)
我的服务:
[ServiceContract]
public interface INotifyService
{
[OperationContract]
void SendEmail(string to, string from, string message);
}
class NotifyService : INotifyService
{
private IEmailRepository emailRepo;
public NotifyService(IEmailRepository emailRepo)
{
if (emailRepo== null) throw new ArgumentNullException("emailRepo");
this.emailRepo= emailRepo;
}
public void SendEmail(string to, string from, string message)
{
//do stuff here
}
}
Run Code Online (Sandbox Code Playgroud)
利用这些信息,我怎么依赖注入MyEmailRepository的NotifyService?
如果我没有默认构造函数,wcf会抛出一个错误请求一个.如果有帮助,我也有使用ninject和asp.net mvc3的经验.
如何change在骨干视图中触发文本框上的事件?
我试过了:
events: {
"onChanged input.autocomplete": "update"
}
Run Code Online (Sandbox Code Playgroud)
update没有被解雇.我也试过了change.
textchange的事件名称是什么?
这是一个家庭作业问题:
解释例程类型在部分参数化中经历的转换。
到目前为止我理解柯里化。但我找不到任何关于编译器如何在内存中实现这样的函数的资源。我能否指出正确的方向,也许是要搜索的关键字或资源链接,或者可能是编译器如何生成类型和符号表以及与问题相关的其他内容的解释。
谢谢。
下面告诉我 GMap2 没有定义。但是使用 GMap2 的代码在回调中。
$(function() {
$('#sample').click(function() {
$.getScript("http://maps.google.com/maps?file=api&v=2&sensor=true&key=API_KEY_HERE", function() {
var map = new GMap2(document.getElementById("mapTest"));
map.setCenter(new GLatLng(18, -77.4), 13);
map.setUIToDefault();
});
});
});
<a id="sample">Click Me</a>
<div id="mapTest" style="width: 200px; height: 100px;"></div>
Run Code Online (Sandbox Code Playgroud) 我的UserRepository中有一个问题,我想在其中更新用户.除非指定,否则我不希望更新某些字段,例如密码.例如,当我将用户从视图传递到服务器到存储库时,它会向用户发送空密码或空密码字符串.这个null被写入数据库(我不想要).
我该如何处理这样的情况?
域
public class User
{
public int UserId { get; set; }
public string Email { get; set; }
public string Password { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
知识库
public User Save(User user)
{
if (user.UserId > 0)
{
User dbUser = context.Users.FirstOrDefault(u => u.UserId == user.UserId);
//What do I do here?
}
context.Users.AddObject(user);
context.SaveChanges();
return user;
}
Run Code Online (Sandbox Code Playgroud)
让我们说在这种情况下,我的视图只允许我更改Email,因此唯一被发送回Save()方法的是:user.UserId而user.Emailwhile user.Password是null.在我的情况下,数据库抛出错误,因为密码应该可以为空.
它必须包含microsoft.ajax javascript文件才能使用如下代码:
@Ajax.BeginForm()
Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×4
javascript ×2
automapper ×1
backbone.js ×1
currying ×1
git ×1
google-maps ×1
jquery ×1
listbox ×1
listboxitem ×1
ninject ×1
silverlight ×1
wcf ×1