草庐IT

c# - 如何覆盖 Razor 的 "name"HtmlAttribute

@Html.RadioButtonFor(Model=>Model.Location,"Location")@Html.LabelFor(Model=>Model.Location,"Location")@Html.RadioButtonFor(Model=>Model.Model,"Model")@Html.LabelFor(Model=>Model.Model,"Model")@Html.RadioButtonFor(Model=>Model.MovableUnit,"MU")@Html.LabelFor(Model=>Model.MovableUnit,"MU")Location

c# - MVC 错误 : The model item passed into the dictionary is null

我只是想建立一个View,但我收到以下错误:System.InvalidOperationException:Themodelitempassedintothedictionaryisnull,butthisdictionaryrequiresanon-nullmodelitemoftype'System.DateTime现在,我知道为什么会出现这种情况,数据库中的特定字段是空值,但它应该是空值,因为这是稍后编辑的内容。这是我的代码:ActionpublicActionResultView(Int64?Id){ModelContainerctn=newModelContainer();

c# - 有没有更快的方法来检查这是否是有效日期?

有没有比下面更简单地捕获异常的更快方法?try{date=newDateTime(model_.Date.Year,model_.Date.Month,(7*multiplier)+(7-dow)+2);}catch(Exception){//Thisisaninvaliddate} 最佳答案 StringDateString=String.Format("{0}/{1}/{2}",model_.Date.Month,(7*multiplier)+(7-dow)+2),model_.Date.Year);DateTimedateTi

c# - 当部分 View 位于共享文件夹中时,ASP.NET MVC '@model dynamic' 无法识别模型属性

不重复:MVCRazordynamicmodel,'object'doesnotcontaindefinitionfor'PropertyName'根据那里的答案,AccordingtoDavidEbbo,youcan'tpassananonymoustypeintoadynamically-typedviewbecausetheanonymoustypesarecompiledasinternal.SincetheCSHTMLviewiscompiledintoaseparateassembly,itcan'taccesstheanonymoustype'sproperties.为什

c# - ASP.NET Identity - 多提供商自定义实现

我目前正在为汽车经销商做一个大项目,但我进退两难。我应该使用ASP.NETIdentity还是老式的FormsAuthentication?我需要能够通过2个提供商登录。首先,用户始终在数据库中,但我们检查它是否是LDAP用户,如果是,则通过LDAP对其进行身份验证(我使用具有登录方法的WebService)。这是我的登录方法:[HttpPost][AllowAnonymous][ValidateAntiForgeryToken]publicasyncTaskLogin(LoginModelmodel){if(ModelState.IsValid){varuserInDb=this.d

c# - 如何将复选框映射到 MVC 模型成员?

我有一个MVCView"%>我有一个带有一组复选框的HTML标记的表单:YourchoiceOptiononeOptiontwo我有一个Controller-Action对classMyController:Controller{[AcceptVerbs(HttpVerbs.Post)]publicActionResultRequestStuff(ModelDatadata){}}并且在提交表单时调用该操作。如何将复选框映射到ModelData的成员(以及我必须将哪些成员添加到ModelData)以便在提交表单时data存储有关哪些复选框被选中的信息? 最佳

c# - 扩展 ASP.NET 身份角色 : IdentityRole is not part of the model for the current context

我正在尝试在我的MVC5应用程序中使用新的ASP.NETIdentity,特别是我正在尝试将ASP.NETIdentity集成到现有数据库中。我已经阅读了有关DBFirst和ASP.NETIdentity的SO问题/答案,并且遵循了所有建议我仍然无法向我的数据库添加角色,尽管我在添加用户时没有问题。这是我的代码:varcontext=newPayrollDBEntities();varroleManager=newRoleManager(newRoleStore(context));boolroleExists=roleManager.RoleExists(roleDto.Name);

c# - ASP.NET MVC : Views using a model type that is loaded by MEF can't be found by the view engine

我正在尝试创建一个框架,以允许将Controller和View动态导入到MVC应用程序中。到目前为止,它是这样工作的:我正在使用.NET4、ASP.NETMVC3RC和RazorViewEngine每个项目都使用MEF导出和导入Controller-我将给定项目中的一组Controller和View称为“模块”BuildManager使用应用前启动方法和BuildManager.AddReferencedAssembly动态引用使用MEF发现的程序集。使用构建事件将二进制文件(来自导出项目)和View复制到目标项目的文件夹结构中使用自定义Controller工厂选择Controller

c# - 如何在 ASP.NET MVC Razor 中有条件地显示字段?

我对C#和ASP.NETMVCRazor还很陌生。如果该字段不为空,我想在我的View中显示该字段。代码@Html.LabelFor(model=>model.phone2)@Html.EditorFor(model=>model.phone2)@Html.ValidationMessageFor(model=>model.phone2)现在,我想先输出如果model.phone2is""行否则输出:如何使用ASP.NETMVCRazor执行此操作? 最佳答案 语法可能不完美,但试试这个:@{vartrClass=string.Is

c# - OData 和 WebAPI : Navigation property not present on model

我正在尝试使用EntityFramework、WebAPI、OData和Angular客户端组合一个简单的玩具项目。一切正常,除了我在其中一个模型上放置的导航属性似乎不起作用。当我使用$expand调用我的API时,返回的实体没有它们的导航属性。我的类是Dog和Owner,看起来像这样:publicclassDog{//Properties[Key]publicGuidId{get;set;}publicStringName{get;set;}[Required]publicDogBreedBreed{get;set;}publicintAge{get;set;}publicintWe