asp.net-core-mvc

ASP.NET Core NullReferenceException when just accessing model

无人久伴 提交于 2019-12-01 04:19:27
I am having trouble with attempting to create a view with a strongly typed model. No matter what I pass in as the model to a View() , I always receive a NullReferenceException when even just accessing the Model . I can't even check if the model is null before executing the rest of the razor page; simply doing a if (Model != null) also throws the same NullReferenceException . Index.cshtml @page @model EncodeModel @{ Layout = "~/Pages/Shared/_Layout.cshtml"; } <h2>Encode</h2> <div id="progress"> @await Html.PartialAsync("~/Encoder/MVC/EncodeProgress.cshtml", new EncodeModule()) </div>

MVC6 TagHelpers with disposable

故事扮演 提交于 2019-12-01 04:09:35
问题 In the older MVC HTML Helpers, one could use IDisposable to wrap content - for example the BeginForm helper would automatically wrap *stuff* with a closing form tag <% using (Html.BeginForm()) {%> *stuff* <% } %> Is this wrapping of content supported with MVC6 TagHelpers? For example I would like this <widget-box title="My Title">Yay for content!</widget-box> to be expanded into a bootstrap widget-box with wrapping divs: <div class="widget-box"> <div class="widget-header"> <h4 class="widget

How can I retrieve AppSettings configuration back in Asp.Net MVC 6?

自古美人都是妖i 提交于 2019-12-01 04:04:55
Assuming that I am using the new DepencyInjection framework to configure my classes and dependencies in the new ASP.Net/vNext. How can I use, How can I get my pre-defined configuration settings? public void ConfigureServices(IServiceCollection services) { // Add Application settings to the services container. services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings")); // Add EF services to the services container. services.AddEntityFramework() .AddSqlServer() .AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]

Using remote validation with ASP.NET Core

大兔子大兔子 提交于 2019-12-01 03:58:29
问题 I am trying to create a remote validation as follows: [Remote("CheckValue", "Validate", ErrorMessage="Value is not valid")] public string Value { get; set; } I am using ASP.NET Core (ASP.NET 5) and it seems Remote is not available. Does anyone know how to do this with ASP.NET CORE? 回答1: The RemoteAttribute is part of ASP.Net MVC Core: If you are using RC1, it is in the Microsoft.AspNet.Mvc namespace. See RemoteAttribute in github. After the renaming planned in RC2, it will be in the Microsoft

How to set the request timeout for one controller action on IIS and IIS Express

心已入冬 提交于 2019-12-01 03:33:59
问题 I need to increase the request timeout for a specific controller action in my application programmatically in the controller. 回答1: The best way I have found so far to handle a long running script (if your application simply can't avoid having one) is to firstly create an async handler: public async Task<IActionResult> About() { var cts = new CancellationTokenSource(); cts.CancelAfter(180000); await Task.Delay(150000, cts.Token); return View(); } In the snippet above I have added a

Loading of references in EF7

会有一股神秘感。 提交于 2019-12-01 03:17:52
问题 I'm having two classes - author and blogpost: public class Author { public Author() { Blogposts = new HashSet<Blogpost>(); } public int Id { get; set; } public string Name { get; set; } public virtual ICollection<Blogpost> Blogposts { get; set; } } and public class Blogpost { public Blogpost() { } // Properties public int Id { get; set; } public string Text { get; set; } public int AuthorId { get; set; } public Author Author { get; set; } } Using EF7 (beta4), I'm connecting them the following

Update Database after Model Changes - Entity Framework 7

人盡茶涼 提交于 2019-12-01 03:08:02
问题 I have created an app using the lastest ASP.NET5 MVC 6 Entity Framework 7 and setup migrations using dnx . ef migration add Initial dnx . ef migration apply This works but when I make a change to the model the database is not updated. I would like to have the database automatically update after a model change when I run the program. My research only points me to old information that doesn't seem to be appropriate to Entity Framework 7. My current code: public ApplicationDbContext(): base() {

How to Determine the ASP.NET Core Environment in my Gulpfile.js

久未见 提交于 2019-12-01 03:07:11
I am using ASP.NET Core MVC 6 using Visual Studio 2015. In my gulpfile.js script I want to know if the hosting environment is Development, Staging or Production so that I can add or remove source maps (.map files) and do other things. Is this possible? UPDATE Relevant issue on GitHub . You can use the ASPNETCORE_ENVIRONMENT (Was formerly ASPNET_ENV in RC1) environment variable to get the environment. This can be done in your gulpfile using process.env.ASPNETCORE_ENVIRONMENT . If the environment variable does not exist, you can fallback to reading the launchSettings.json file which Visual

Razor page can't see referenced class library at run time in ASP.NET Core RC2

谁说我不能喝 提交于 2019-12-01 02:25:07
I started a new MVC Web Application project for the RC2 release and I'm trying to add a class library as a project reference. I added a simple class library to my project and referenced it and got the following in the project.json file: "frameworks": { "net452": { "dependencies": { "MyClassLibrary": { "target": "project" } } } }, I can use this library in any of the Controllers and the Startup.cs files without any trouble but I get the following error at run time when I try and use the library from a Razor page: The name 'MyClassLibrary' does not exist in the current context Output.WriteLine

How to use active Directory for ASP.Net 5 (MVC6) Intranet application

雨燕双飞 提交于 2019-12-01 02:13:21
问题 I am developing an intranet application and would like to use the existing organisations Active Directory for user authentication and policy based role authorisation. Can someone point me in the right direction? I am getting a bit confused (well actually a lot confused). Thankyou 回答1: Per Authentication and Autorization resources under http://docs.asp.net/en/latest/security/index.html First start a new ASP.Net Web Application project, Pick the Web Application template then on the right pane