我可以让本教程在新项目中工作,但不能在我现有的项目中工作.
我的项目是一个ASP.Net MVC 4 Web应用程序,在web.config文件中具有以下属性:
<appSettings>
<add key="webpages:Enabled" value="true"/>
</appSettings>
Run Code Online (Sandbox Code Playgroud)
这是因为我的应用程序是单页面应用程序,它在客户端使用AngularJS.我的应用程序中唯一的页面是index.cshtml,我已经为signalR添加了相关的代码:
<!-- signalR chat -->
<script src="~/Scripts/jquery.signalR-1.0.0.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="/signalr/hubs"></script>
<!--Add script to update the page and send messages.-->
<script type="text/javascript">
$(function () {
// Declare a proxy to reference the hub.
var chat = $.connection.chatHub;
// Create a function that the hub can call to broadcast messages.
chat.client.broadcastMessage = function (name, message) {
// Html encode display name and message.
var …Run Code Online (Sandbox Code Playgroud) 我在使用AngularJS的ui-router插件时遇到了麻烦:
angular.module('myApp', []).
config(['$routeProvider', '$stateProvider', function($routeProvider, $stateProvider) {
$stateProvider
.state('mandats', {
url: '/domiciliations/mandats',
templateUrl: 'domiciliations/views/mandats.html',
controller: 'mandatsCtrl'
});
}])
Run Code Online (Sandbox Code Playgroud)
然后我在启动时收到此错误:
Unknown provider: $stateProvider
Run Code Online (Sandbox Code Playgroud)
我按此顺序包含了javascripts:
<script src="/Scripts/libs/angular/angular.js"></script>
<script src="/Scripts/libs/angular/angular-resource.js"></script>
<script src="/Scripts/libs/angular/angular-ui-states.js"></script>
Run Code Online (Sandbox Code Playgroud)
可能是什么问题 ?
[编辑]
我通过添加'ui.compat'作为myApp的依赖项来摆脱错误消息.我在ui-router的示例代码中看到了这一点,但在文档中没有.这是关于什么的?
尽管如此,它仍然无效.我已将ui-view添加到应用程序索引文件中的div.但页面仍然是空白的.
我是mvc 4的新手,我想知道我应该把我的自定义javascript文件放在哪里."自定义"是指仅在特定视图或部分视图中使用的脚本.
我也使用区域,因此增加了复杂性.我正在考虑将我的脚本放在应用程序根目录下的Script文件夹中,然后放在Custom子文件夹中.
那么我如何在我的视图中引用脚本?我应该使用自定义捆绑包吗?
我无法让它发挥作用.当我单击关闭按钮时,没有任何反应.
这是代码:
<div class=" alert alert-error alert-block" style="width:200px" >
<button class="close" data-dismiss="alert">×</button>
<span>errors</span>
</div>
Run Code Online (Sandbox Code Playgroud)
我在jsfiddler上重现了这个问题:http: //jsfiddle.net/graphicsxp/7L7Nd/
编辑
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "quoteWizard" }))
{
<input type="hidden" id="ModelType" value="CarQuoteRequestViewModel" />
ViewBag.ValidationSummaryClass = ViewData.ModelState.IsValid ? "validation-summary-valid" : "validation-summary-errors";
<div class="@ViewBag.ValidationSummaryClass alert alert-error in fade" data-valmsg-summary="true">
<button class="close" data-dismiss="alert">×</button>
<span>Before you can continue, please make sure you have completed the mandatory fields
highlighted below.</span>
<ul style="display: none" />
</div>
@RenderSection("QuoteSection")
<div class="ui-formwizard-nav">
<input id="back" value="@Resource.Global.Previous" type="reset" class="btn …Run Code Online (Sandbox Code Playgroud) 我已经定义了我的主模块:
angular.module('domiciliations', ['domiciliations.service', 'loggerService', 'person.directives']).
config(['$routeProvider', function ($routeProvider) {
$routeProvider.
when('/domiciliations/mandats', { templateUrl: 'domiciliations/views/mandats.html', controller: mandatsCtrl }).
when('/domiciliations/mandats/:rum', { templateUrl: 'domiciliations/views/mandat.html', controller: mandatCtrl }).
otherwise({ redirectTo: '/domiciliations/mandats' });
}]).
value('toastr', window.toastr).
value('breeze', window.breeze);
Run Code Online (Sandbox Code Playgroud)
我的问题是如何在我的控制器中指定模块依赖项?
如果我做:
angular.module('domiciliations.service', ['ngResource', 'breeze', 'loggerService']).
factory('Domiciliation', function ($resource, breeze, logger) {
}
Run Code Online (Sandbox Code Playgroud)
然后我得到一个错误'没有模块:微风'.
它适用于我:
angular.module('domiciliations.service', ['ngResource']).
factory('Domiciliation', function ($resource, breeze, logger) {
}
Run Code Online (Sandbox Code Playgroud)
那我怎么想在微风和记录器上指定依赖?
我已经设法在HTML中获得ng-指令的intellisense.我也获得了大多数javascript文件的intellisense.但是,我不知道如何为注入的位获取智能感知.考虑以下:
function mandatsCtrl($scope, Domiciliation, logger, $q) {
}
Run Code Online (Sandbox Code Playgroud)
如何获得$ q或$ scope的intellisense,这是注入?
我注意到如果日期属性从服务器返回值为"2013-07-11T17:11:04.700",则breeze将值更改为Thu Jul 11 19:11:04 UTC + 0200 2013.
注意现在时间提前2个小时!
保存实体时我已经遇到过这个问题,所以我必须使用momentjs显式转换我的日期属性:
date.hours(date.hours() - moment().zone() / 60);
Run Code Online (Sandbox Code Playgroud)
但现在看来,在进行读操作时也会出现问题.
什么是确保微风不会改变我的日期属性值的最佳方法?
我已将以下命名空间添加到我的Views web.config文件中:
<add namespace="System.Web.Mvc.Html5" />
Run Code Online (Sandbox Code Playgroud)
现在的问题是,在Views中,我只能使用全名来使用类型:
@System.Web.Mvc.Html5.InputTypes.Html5TextBox()
Run Code Online (Sandbox Code Playgroud)
我希望能够做到:
@InputTypes.Html5TextBox()
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点 ?
我正在使用@html.EditorFor在编辑模式下渲染我的模型,并且不会渲染下拉列表.
这是我的ViewModel:
public class RiskAutoViewModel
{
public RiskAutoViewModel()
{
VehicleMakeList = new SelectList(new List<VehicleMake>() { new VehicleMake() { Id = 1, Name = "Renault" }, new VehicleMake() { Id = 2, Name = "Peugeot" } });
}
public int NoClaimsDegree { get; set; }
public int VehicleValue { get; set; }
public int EngineCapacity { get; set; }
public int VehicleMake { get; set; }
public SelectList VehicleMakeList { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
VehicleMake呈现为文本框,VehicleMakeList …
我发现使用托管标识连接到 Azure KeyVault 很容易。该文档显示了如何做到这一点:
var azureServiceTokenProvider = new AzureServiceTokenProvider();
var keyVaultClient = new KeyVaultClient(
new KeyVaultClient.AuthenticationCallback(
azureServiceTokenProvider.KeyVaultTokenCallback));
config.AddAzureKeyVault(
$"https://{builtConfig["KeyVaultName"]}.vault.azure.net/",
keyVaultClient,
new DefaultKeyVaultSecretManager());
Run Code Online (Sandbox Code Playgroud)
然后我意识到它需要Microsoft.Azure.KeyVault已弃用的包。所以我正在努力弄清楚如何使用 SDK 4 执行上述操作。我找到的所有文档都与 SDK 3 相关。
[编辑] 我发现以下代码可以使用带有 SDK 4 的托管标识来获取 azure KeyVault Secret。但是我看不到如何将它添加到我的配置中。它曾经是通过 config.AddAzureKeyVault()Microsoft.Extensions.Configuration.AzureKeyVault 包完成的,但它与 SDK 4 SecretClient 不兼容:
return Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, config) =>
{
var azureCredentialOptions = new DefaultAzureCredentialOptions();
var credential = new DefaultAzureCredential(azureCredentialOptions);
var secretClient = new SecretClient(new System.Uri("https://mykeyvault.vault.azure.net/"), credential);
var secret = secretClient.GetSecret("StorageConnectionString");
config.AddAzureKeyVault()
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
}); …Run Code Online (Sandbox Code Playgroud) angularjs ×4
breeze ×2
angular-ui ×1
asp.net ×1
asp.net-mvc ×1
azure ×1
bundle ×1
css3 ×1
date ×1
dependencies ×1
html-select ×1
html5 ×1
intellisense ×1
javascript ×1
namespaces ×1
signalr ×1