我有一个功能CreatePerson(int id)
,我想通过id
从@Url.Action
.
以下是参考代码:
public ActionResult CreatePerson(int id) //controller
window.location.href = "@Url.Action("CreatePerson", "Person") + id";
Run Code Online (Sandbox Code Playgroud)
上面的代码无法将id
值传递给CreatePerson
函数.
拥有以下服务构造函数
public class Service : IService
{
public Service(IOtherService service1, IAnotherOne service2, string arg)
{
}
}
Run Code Online (Sandbox Code Playgroud)
使用.NET Core IOC机制传递参数有哪些选择?
_serviceCollection.AddSingleton<IOtherService , OtherService>();
_serviceCollection.AddSingleton<IAnotherOne , AnotherOne>();
_serviceCollection.AddSingleton<IService>(x=>new Service( _serviceCollection.BuildServiceProvider().GetService<IOtherService>(), _serviceCollection.BuildServiceProvider().GetService<IAnotherOne >(), "" ));
Run Code Online (Sandbox Code Playgroud)
还有其他方法吗?
c# dependency-injection ioc-container .net-core asp.net-core
我正在关注文档以创建初始迁移。执行时dotnet
,我得到了帮助部分,这意味着PATH可以正常工作。
然后,我尝试从控制台窗口的文档中执行以下命令:
dotnet ef migrations add InitialCreate
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Run Code Online (Sandbox Code Playgroud)Could not execute because the specified command or file was not found. Possible reasons for this include: * You misspelled a built-in dotnet command. * You intended to execute a .NET Core program, but dotnet-ef does not exist. * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
- 自从复制命令以来,我排除了第一项。
- 由于安装了软件包Microsoft.EntityFrameworkCore.SqlServer,因此我排除了第二项。
- 我排除了第三项,因为调用dotnet时会获得帮助部分。
我正在搜索该问题,但是由于该版本是新版本,因此没有太多工作要做,并且/或者它淹没了早期版本中的类似问题。 …
c# entity-framework-core .net-core asp.net-core .net-core-3.0
我试图将我的应用程序从 asp.net core 2.1 迁移到 3.0,并且在 program.cs 中出现了第一个建议的更改以创建主机。
asp.net core 2.1 程序.cs
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
Run Code Online (Sandbox Code Playgroud)
asp.net core 3.0 程序.cs
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
Run Code Online (Sandbox Code Playgroud)
我可以看到,在 asp.net core 3.0 中,它正在创建 Host 而不是 WebHost 并在创建 Host 时注入 WebHostBuilder。
但是我在这里没有明确的想法 Host 和 WebHost 之间有什么区别以及为什么 asp.net core 3.0 应用程序不允许创建 WebHost?
在RC1中,IUrlHelper
可以注入服务(services.AddMvc()
在启动类中)
这在RC2中不再起作用.有没有人知道如何在RC2中做到这一点,因为刚刚UrlHelper
需要一个ActionContext
对象.不知道如何在控制器之外得到它.
当我阅读关于webapi以响应请求和处理错误时,一切都基于:
IHttpActionResult
HttpResponseException
Run Code Online (Sandbox Code Playgroud)
但是当您创建.net核心webapi项目时,这些项目不可用.我能找到IActionResult,它似乎相当于?
但是我要绕圈试图找出一个非常简单的东西,即如何处理.net核心webapi中的错误,因为HttpResponseException不可用.我得到的印象是"http"中的所有内容,仅适用于完整的MVC应用程序.
我想做的就是返回一个错误,当然它必须简单......
我现在真的很困惑,因为我得到了ERROR TypeError: "_this.device.addKeysToObj is not a function"
.但我实现了这个功能,所以我不知道问题是什么或为什么它不可调用.我已经尝试使用Firefox和chrome的代码,两者都是通过相同的错误.
错误符合 this.device.addKeysToObj(this.result.results[0]);
这是我的班级:
export class Device {
id: number;
deviceID: string;
name: string;
location: string;
deviceType: string;
subType: string;
valueNamingMap: Object;
addKeysToObj(deviceValues: object): void {
for (let key of Object.keys(deviceValues).map((key) => { return key })) {
if (!this.valueNamingMap.hasOwnProperty(key)) {
this.valueNamingMap[key] = '';
}
}
console.log(this, deviceValues);
}
}
Run Code Online (Sandbox Code Playgroud)
这就是电话:
export class BatterieSensorComponent implements OnInit {
@Input() device: Device;
public result: Page<Value> = new Page<Value>();
//[..]
ngOnInit() {
this.valueService.list('', this.device).subscribe(
res => …
Run Code Online (Sandbox Code Playgroud) 我有一个简单的AngularJs应用程序设置,看起来有点像这样:
client
vendor
angular
bootstrap
jquery
...
app.module.js
app.controller.js
...
node_modules
angular-mocks
...
Run Code Online (Sandbox Code Playgroud)
我正在设置一个karma.conf.js
文件,我想要包含angular\angular.js
来自vendor
.我不想包含任何其他内容vendor
.
以下是我在相关karma.conf.js
部分的内容:
files: [
'client/vendor/angular/angular.js',
'client/**/*.js',
'client/**/*.spec.js'
],
exclude: [
'client/vendor/**/*.js'
],
Run Code Online (Sandbox Code Playgroud)
我遇到的问题很简单:我angular.js
明确地包括在内files
,但它在exclude
部分模式中被排除在外.
我怎样才能排除client/vendor
除angular/angular.js
(以后可能是其他人)以外的所有内容?该client
目录包含许多文件,子文件夹等,其中包含我自己的.js文件,因此仅将我想要包含的所有内容移动到自己的文件夹中并不容易.
自ASP.NET Core 2.1发布以来,我正在使用新的Identity UI软件包.使用新生成的MVC项目,这里有一些可用的页面URL:
/Home/About
/Home/Contact
/Identity/Account/Login
/Identity/Account/Register
Run Code Online (Sandbox Code Playgroud)
如何配置路由以/Identity/
从URL中删除部分?
我正在尝试在Angular中发出请求,我知道HTTP响应不是JSON而是文本.但是,Angular似乎期待JSON响应,因为错误如下:
SyntaxError:XMLHttpRequest.c中JSON.parse()位置0的JSON中的意外标记<
以及
解析http:// localhost:9时出现 Http失败...
这是post方法:
return this.http.post(this.loginUrl, this.createLoginFormData(username, password), this.httpOptions)
.pipe(
tap( // Log the result or error
data => console.log(data);
error => console.log(error)
)
);
Run Code Online (Sandbox Code Playgroud)
和标题.
private httpOptions = {
headers: new HttpHeaders({
'Accept': 'text/html, application/xhtml+xml, */*',
'Content-Type': 'application/x-www-form-urlencoded',
responseType: 'text'
},
) };
Run Code Online (Sandbox Code Playgroud)
我认为这responseType: 'text'
足以让Angular期望非JSON响应.
c# ×7
asp.net-core ×6
.net-core ×2
angular ×2
javascript ×2
typescript ×2
angularjs ×1
asp.net-mvc ×1