如何在MVC 2中设置TextBox的MaxLength和Size?关于SO的问题已经提出了几个问题.作为MVC的新手,我发现没有一个解决方案似乎有效 - 可能是因为我做得不对.
无论如何,我想知道是否有更好的解决方案,因为之前的问题似乎是在MVC 2处于测试阶段时提出的.
我升级的应用程序的新构建失败了.升级适用于.Net Framework 4.0到4.5和EF到版本6.错误消息是;
Models\Mapping\vw_EmployeesAndJobTitlesMap.cs(47):找不到类型名称"DatabaseGeneratedOption".此类型已转发到程序集'System.ComponentModel.DataAnnotations,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'.考虑添加对该程序集的引用.
在日志中我得到以下内容;
为默认目标构建$/SCD4/SCD4.Model/SCD4.Model.csproj.metaproj.
00:00为默认目标构建$/StandardClassLibrary/StandardClassLibrary/StandardClassLibrary/StandardClassLibrary.csproj.
00:01为默认目标构建$/SCD4/SCD4.Model/SCD4.Model.csproj.c:\ Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(847):找不到框架".NETFramework,Version = v4.5"的引用程序集.要解决此问题,请为此框架版本安装SDK或Targeting Pack,或者将应用程序重新定位到已安装SDK或Targeting Pack的框架版本.请注意,程序集将从全局程序集缓存(GAC)中解析,并将用于代替引用程序集.因此,您的程序集可能无法正确定位到您想要的框架.c:\ Builds\1\SCD4\SCD4 - Test\Sources\MVC4\SCD4\packages\EntityFramework.6.0.2\lib \nett\EntityFramework.dll:引用类型'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption'声明它在'c:\ Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll'中定义,但无法找到它:c:\ Builds\1\SCD4\SCD4 - Test\Sources\MVC4\SCD4\packages\EntityFramework.6.0.2\lib \nett\EntityFramework.dll:引用类型'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption'声明它在'中定义' c:\ Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll',但无法找到c:\ Builds\1\SCD4\SCD4 - Test\Sources\MVC4\SCD4\packages\EntityFramework.6.0.2\lib \nett\EntityFramework.dll:引用类型'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOpt ion'声称它在'c:\ Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll'中定义,但无法找到c:\ Builds\1\SCD4\SCD4 - Test\Sources\MVC4\SCD4\packages\EntityFramework.6.0.2\lib \nett\EntityFramework.dll:引用类型'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption'声明它在'c:\ Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll'中定义,但无法找到它:c:\ Builds\1\SCD4\SCD4 - Test\Sources\MVC4\SCD4\packages\EntityFramework.6.0.2\lib \nett\EntityFramework.dll:引用类型'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption'声明它在'中定义' c:\ Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll',但它 找不到Models\Mapping\vw_EmployeesAndJobTitlesMap.cs(24):找不到类型名称"DatabaseGeneratedOption".此类型已转发到程序集'System.ComponentModel.DataAnnotations,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'.考虑添加对该程序集的引用.
当我点击日志中的链接时,这条线似乎就是问题;
using System.ComponentModel.DataAnnotations.Schema;
Run Code Online (Sandbox Code Playgroud)
EF是版本6.错误消息说不c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll存在,但是当我看它确实存在时.
我的日志文件看起来像;
Build build 20/02/2014 14:38:54 节点1上的项目"C:\ Builds\2\SCD4\SCD4 - Test\Sources\MVC4\SCD4\SCD4.sln"(默认目标).ValidateSolutionConfiguration:构建解决方案配置"Debug | Any CPU".项目"C:\ Builds\2\SCD4\SCD4 - Test\Sources\MVC4\SCD4\SCD4.sln"(1)正在构建"C:\ Builds\2\SCD4\SCD4 - Test\Sources\MVC4\SCD4 \节点1上的SCD4\SCD4.csproj.metaproj"(2)(默认目标).项目"C:\ Builds\2\SCD4\SCD4 …
我正在使用免费的jqGrid.
我的网页是;
<div id="hiddenFields"
data-sir-get-properties-list="@Url.Action("GetAllProperties", "DataContract")"></div>
<section id="SelectContract" class="contractSelectedPage" style="clear: both;">
<fieldset>
<legend>@ViewBag.Title</legend>
<div id="divLoading" class="has-error">Loading ...</div>
<table id="grid"></table>
<div id="pager"></div>
</fieldset>
</section>
Run Code Online (Sandbox Code Playgroud)
我的jquery是;
$(function () {
getGrid();
});
var populateGrid = function (data) {
var grid = $("#grid");
grid.jqGrid({
data: data,
colNames: ["", "", "Address", "", "", "Inspection Visits", "Category", "Status"],
colModel: [
{ name: 'InspectionId', index: 'InspectionId', width: 65, align: 'center', hidden: true },
{ name: 'InspectionStatusId', index: 'InspectionStatusId', width: 65, align: 'center', hidden: true },
{ name: …Run Code Online (Sandbox Code Playgroud) 我有一个使用Web Core API的MVC网站.在进行了微小的更改和部署之后,我意外地收到了错误; 响应状态代码不表示成功:500(内部服务器错误).所以我启用了Web Core API的日志文件(请参阅https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/troubleshoot?view=aspnetcore-2.0#aspnet-core -module-stdout-log)我收到此错误消息;
应用程序启动异常:System.Collections.Generic.KeyNotFoundException:给定的键不存在于字典中.Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.CandidateResolver.ComputeClassification(String依赖项)中的Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.CandidateResolver.ComputeClassification(String依赖项)中的System.Collections.Generic.Dictionary2.get_Item(TKey键)在Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.CandidateResolver.ComputeClassification(字符串依赖)在Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.CandidateResolver.d__4.MoveNext()在System.Linq.Enumerable.d__172.MoveNext()在系统.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()at Microsoft.Extensions.DependencyInject.MvcCoreServiceCollectionExtensions.GetApplicationPartManager(IServiceCollection services)at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(IServiceCollection services)at Properties.API.Startup.ConfigureServices(IServiceCollection) SER 恶意)---抛出异常的前一个位置的堆栈跟踪结束---在Microsoft.AspNetCore的Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection服务)的System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()处. Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()中的Hosting.Internal.WebHost.EnsureApplicationServices()主机环境:暂存内容根路径:C:\ inetpub\wwwroot\SIR现在正在侦听:http:// localhost:33007申请开始了.按Ctrl + C关闭.
更新:它倒下的线是;
services.AddMvcCore()AddJsonFormatters();
在ConfigureServices中.
我如何调试它以找出导致这种情况的原因?
public class Startup {
public Startup(IHostingEnvironment env) {
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appSettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($ "appSettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
Run Code Online (Sandbox Code Playgroud)
.
.
.
Run Code Online (Sandbox Code Playgroud)public void ConfigureServices(IServiceCollection services) { services.AddCors(); services.AddMvcCore().AddJsonFormatters(); services.Configure<IISOptions>(options => new IISOptions { AutomaticAuthentication = true, ForwardClientCertificate = false, ForwardWindowsAuthentication …
有很多值得赞扬的MVC,但我一直遇到的一个问题是ID名称冲突.我在使用foreach循环生成网格时首先注意到它.在SO的帮助下,我发现解决方案是使用编辑器模板.现在我对标签有同样的问题.我用这个参考来找出如何使用标签; http://blog.roonga.com.au/search?updated-max=2010-06-14T19:27:00%2B10:00&max-results=1
The problem with my tabs is that I am using a date field with a date picker. In the example above, ID name collisions are avoided by referencing a generated unique Id of the container element. However for a datepicker, the ID of the container is irrelevant, only the ID of the date field matters. So what happens is that if I create my second tab the same as the first, when I update my second tab, the …
我的表单由2列表格式化.在左栏中,我使用a <label>和右列a <input type="text">.某些输入框是必需的.因此要求是对于所有强制性输入,标签旁边应该有一个红色星号.但是,标签的设计使其始终跟着换行符,因此星号会自动进入下方.确保不会发生这种情况的最佳方法是什么,并且星号位于标签旁边的正确位置?我认为该<div float="left>选项不适用于表格.这是所要求的代码;
<tr>
<td class="leftCell"><span style="white-space: nowrap;"><label for="Subcontractor_CompanyName">Company</label><span style="display: inline;" class="errorHighlight">*</span></span></td>
<td class="rightCell"><input style="width: 300px;" id="Subcontractor_CompanyName" name="Subcontractor.CompanyName" value="096 club" type="text" data-val-required="Must enter the Company Name" data-val="true">
<span class="field-validation-valid" data-valmsg-replace="false" data-valmsg-for="Subcontractor.CompanyName">*</span></td>
</tr>
Run Code Online (Sandbox Code Playgroud)
我试图使用<span style="white-space: nowrap;">失败.
我正在使用Active Directory为我的Web应用程序中的用户分配角色.但是,我发现在更改AD中的用户安全组分配与传播给正在使用该应用程序的用户的更改之间似乎存在很长时间的延迟.实际上,当我从AD检索C#中的用户角色时,它们是最新的,但是当我运行此代码来查看用户的角色时,它们直到第二天才会更新.如何从AD即时进行用户角色更新?
var identity = WindowsIdentity.GetCurrent();
var groups = from sid in identity.Groups select sid.Translate(typeof(NTAccount)).Value;
foreach (var group in groups)
{
groupName = group;
}
Run Code Online (Sandbox Code Playgroud) 我的Web Core API中的此代码确认我是经过身份验证的用户,但我没有获取用户名,而是获取应用程序池的名称.我该如何解决?
var testa = User.Identity.GetType();
NLogger.Info($"testa = {testa}");
var testd = User.Identity.IsAuthenticated;
NLogger.Info($"testd = {testd}");
var loggedInUser = User.Identity.Name;
NLogger.Info($"loggedInUser = {loggedInUser}");
Run Code Online (Sandbox Code Playgroud)
在我的日志文件中,我得到;
testa = System.Security.Principal.WindowsIdentity
testd = True
loggedInUser = IIS APPPOOL\SIR.WEBUI
Run Code Online (Sandbox Code Playgroud)
我使用控制器的[Authorize]标签并禁用匿名身份验证.
好吧,我从Postman调用方法,它工作正常,LoggedInUser是正确的.但是当我从我的代码中调用时,我得到了上面显示的不正确的loggedInUser.我用来从我的客户端应用程序调用web api的代码是;
public static async Task<IEnumerable<ContractDto>> GetAllForUser()
{
using (var client = new HttpClient(new HttpClientHandler { UseDefaultCredentials = true }))
{
client.BaseAddress = new Uri(AppSettings.ServerPathApi);
var path = GetPath("getallforuser");
var response = await client.GetAsync(path);
response.EnsureSuccessStatusCode();
var stringResult = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<IEnumerable<ContractDto>>(stringResult);
}
} …Run Code Online (Sandbox Code Playgroud) 这是一个VSTS问题,不要与之前提出的类似问题混淆.此应用程序不使用强名称.我有一个WIN RT遗留项目,证书已用完.所以我有一个新的,我已经设置了密码并将其放入我的项目中.但是,当我运行VSTS构建时,我收到以下错误消息.
C:\ Program Files(x86)\ MSBuild\Microsoft\VisualStudio\v14.0\AppxPackage\Microsoft.AppXPackage.Targets(2557,5)C:\ Program Files(x86)\ MSBuild\Microsoft\VisualStudio\v14.0\AppxPackage\Microsoft.AppXPackage.Targets(2557,5):错误APPX0105:无法导入密钥文件'blah.pfx'.密钥文件可能受密码保护.要更正此问题,请尝试将证书手动导入当前用户的个人证书存储区.
C:\ Program Files(x86)\ MSBuild\Microsoft\VisualStudio\v14.0\AppxPackage\Microsoft.AppXPackage.Targets(2557,5)C:\ Program Files(x86)\ MSBuild\Microsoft\VisualStudio\v14.0\AppxPackage\Microsoft.AppXPackage.Targets(2557,5):错误APPX0102:在证书存储中找不到项目中指定的指纹"11F4B2DBB13F0BDACAEA79617C76279AAB394592"的证书.请在项目文件中指定有效的指纹.
C:\ Program Files(x86)\ MSBuild\Microsoft\VisualStudio\v14.0\AppxPackage\Microsoft.AppXPackage.Targets(2557,5)C:\ Program Files(x86)\ MSBuild\Microsoft\VisualStudio\v14.0\AppxPackage\Microsoft.AppXPackage.Targets(2557,5):错误APPX0107:指定的证书对签名无效.有关有效证书的详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=241478.
进程'msbuild.exe'退出,代码为'1'.
我该如何解决?
我正在努力使用Automapper语法.我有一个PropertySurveys列表,每个包含1个属性.我希望将集合中的每个项目映射到一个新的对象,该对象组合了两个类.
所以我的代码看起来像;
var propertySurveys = new List<PropertyToSurveyOutput >();
foreach (var item in items)
{
Mapper.CreateMap<Property, PropertyToSurveyOutput >();
var property = Mapper.Map<PropertyToSurvey>(item.Property);
Mapper.CreateMap<PropertySurvey, PropertyToSurveyOutput >();
property = Mapper.Map<PropertyToSurvey>(item);
propertySurveys.Add(property);
}
Run Code Online (Sandbox Code Playgroud)
我的简化课程看起来像;
public class Property
{
public string PropertyName { get; set; }
}
public class PropertySurvey
{
public string PropertySurveyName { get; set; }
public Property Property { get; set;}
}
public class PropertyToSurveyOutput
{
public string PropertyName { get; set; }
public string PropertySurveyName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
因此,在PropertyToSurveyOutput对象中,在设置第一个映射PropertyName之后.然后在设置第二个映射PropertySurveyName之后,将PropertyName重写为null.我该如何解决?