Tag: asp.net mvc

如何将模型从视图传递到局部视图?

我的观点不是强类型的。 但是我在这个视图中有一个强类型的局部视图。 如何将模型传递给此强类型视图? 我尝试过类似的东西 public ActionResult Test() { MyData = new Data(); MyData.One = 1; return View(“Test”,MyData) } 在我的TestView中 这给了我一个stackoverflowexception。 所以我不知道如何传递它。 当然,如果可能的话,我不想让测试视图强烈输入,如果我在该视图中有10个强类型的局部视图,我需要像某种包装器。

从多个CDN位置创建脚本包

假设我们的应用程序处于脱机状态,即我们无法使用第三方CDN,因此我们正在创建自己的应用程序。 我想在一个单独的(父)Web应用程序中托管所有供应商脚本,然后将它们包含在其他几个MVC应用程序的捆绑包中。 例如 http://localhost/parentWeb/Scripts/jquery.js http://localhost/parentWeb/Scripts/jquery-ui.js http://localhost/parentWeb/Scripts/globalize.js 我想在ASP.NET MVC App网站中包含: http://localhost/parentWeb/childWeb 即做这样的事情: bundles.UseCdn = true; bundles.Add( new ScriptBundle( “~/bundles/VendorScripts”, “http://localhost/parentWeb/Scripts/jquery.js”, “http://localhost/parentWeb/Scripts/jquery-ui.js”, “http://localhost/parentWeb/Scripts/globalize.js”)); ……当然这是不可能的。 有一个很好的解决方法吗?

根据值选中或取消选中复选框?

我们如何根据值以编程方式选中或取消选中复选框? 也就是说,对于特定用户,如果值为true,则应选中复选框,否则如果值为false,则需要取消选中该复选框。 我按以下方式声明了复选框:

“asp-format”未应用于标记助手

我在mvc 6项目中使用带有taghelper元素的“asp-format”标签时遇到了问题。 我们的想法是以这种方式格式化日期输入元素: 这个“StartDate”属性在我的模型中,以这种方式声明: public DateTime StartDate {get; set; } 出于一个奇怪的原因,这个元素永远不会被格式化,并且总是这样呈现: —> 02/29/2016 00:00:00 所以我创建了一个viewmodel类并定义了一个属性来保存整个人模型。 public class PersonViewModel { public Person Johndoe {get; set; } } 在视图中使用此类,格式化工作。 —> 29/02/2016

Google Chrome的ASP.NET MVC Session.IsNewSession问题

我正在为我的ASP.NET 3.5 MVC 2项目编写一个Session过期的逻辑片段来注销用户并将它们重定向到AccountController LogOn操作。 我对所有关心会话状态的操作都有以下属性,这段代码适用于IE 8,但不适用于Firefox 4或Google Chrome 10.症状是当我尝试导航到由操作表示的视图时我的[SessionExpireFilter]属性,下面代码中的ctx.Session.IsNewSession属性每次都评估为“true”,即使我在30分钟的会话中只有几秒钟。 public class SessionExpireFilterAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { HttpContext ctx = HttpContext.Current; // check if session is supported if (ctx.Session != null && ctx.Session.IsNewSession) { // If it says it is a new session, but an existing cookie exists, then it […]

如何在C#中构建搜索引擎

我正在尝试在ASP.NET MVC中构建一个Web应用程序,并且需要构建一个非常复杂的搜索function。 当用户输入搜索词时,我想搜索各种数据源,包括文档,数据库中的表,网页url和一些像facebook这样的API。 任何提示,教程和提示将不胜感激。

Web API路由 – 找到了与请求匹配的多个操作

我有这条路线: routes.MapRoute( name: “Default”, url: “{controller}/{action}/{id}”, defaults: new { id = UrlParameter.Optional } ); 这个动作: [System.Web.Http.HttpPost] [System.Web.Http.ActionName(“GetLoginSeed”)] public object GetLoginSeed() [System.Web.Http.HttpPost] [System.Web.Http.AllowAnonymous] [System.Web.Http.ActionName(“Authenticate”)] public object PerformLogin(JObject jr) 这是post请求: http://localhost:61971/api/Login/GetLoginSeed 为什么我总是得到多个匹配请求错误的操作?

列表表导致“在数据库中拒绝CREATE TABLE权限”ASP.NET – MVC4

我正在使用ASP.NET MVC 4 – c#连接到实时数据库,并列出结果,但是当我去查看页面时它返回以下错误: CREATE TABLE permission denied in database ‘DatabaseName’. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: CREATE TABLE permission denied in database ‘DatabaseName’. Source Error: […]

实体类型IdentityUser不是当前上下文的模型的一部分

我看到了与这个问题相同的问题,但那里提出的情景似乎并不适用所以我认为我有一个不同的问题。 事实上,我在SO上看到几个相似的问题,每个问题都有不同的原因和解决方案,所以我认为这个错误必须从高水平引起。 那说…… 我有一个EF代码优先数据库模型,我正在尝试使用IdentityUser扩展我的MVC 5站点的标准注册。 我有我的扩展UserModel : namespace MyMvcSite.Models { public class UserModel :IdentityUser { public string BillingId { get; set; } public virtual ICollection Databases { get; set; } } 我的背景: using MyMvcSite.Models; namespace MyMvcSite.Web { public class AuthContext : IdentityDbContext { public AuthContext() : base(“AuthContext”) { } } } 现在,当我执行代码注册用户时: public async Task […]

检查用户是否在asp.net mvc Identity中扮演角色

我在使用用户和角色为数据库播种时遇到了问题。 创建了用户和角色(我可以在抛出错误后在数据库中看到它们)。 但是,当我尝试检查用户是否在角色中时,我得到一个例外。 我的代码是: public class tbInitializer : DropCreateDatabaseAlways { protected override void Seed(tbContext context) { ApplicationDbContext userscontext = new ApplicationDbContext(); var userStore = new UserStore(userscontext); var userManager = new UserManager(userStore); var roleStore = new RoleStore(userscontext); var roleManager = new RoleManager(roleStore); if(!userscontext.Users.Any(x=> x.UserName==”marktest”)) { var user = new ApplicationUser { UserName = “marktest”, Email = […]