我最近将我的项目更新为mvc 5,EF 6.我通过包控制台管理器(update-package)更新了所有软件包.
现在我在每个视图/局部视图/布局中看到大量关于html助手的警告.
这些是一些错误:
这是views/webconfig:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.web>
<httpHandlers> …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个项目,我使用.net web api,knockout,在这个例子中,jquery插件select2.
我想要做的是在选择更改后设置一些字段值.在ajax调用之后加载select2控件列表,并且对象包含的数据不仅仅是id和text.我如何获得剩余的数据,所以我可以用它来填充其他输入?很快,我试图在更改选择后更新视图模型(但是当这个插件进行ajax调用时我得到了数据).
以下是所选对象应包含的示例数据:
{
"Customer":{
"ID":13,
"No":"0000012",
"Name":"SomeName",
"Address":"SomeAddress",
"ZipCode":"324231",
"City":"SimCity",
"Region":"SS",
"Phone":"458447478",
"CustomerLocations":[]
}
}
Run Code Online (Sandbox Code Playgroud)
这是我现在的位置:
示例html:
<input type="hidden" data-bind="select2: { optionsText: 'Name', optionsValue: 'ID', sourceUrl: apiUrls.customer, model: $root.customer() }, value: CustomerID" id="CustomerName" name="CustomerName" />
<input type="text" data-bind="........" />
<input type="text" data-bind="........" />
etc...
Run Code Online (Sandbox Code Playgroud)
这是自定义绑定:
ko.bindingHandlers.select2 = {
init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
var obj = valueAccessor(),
allBindings = allBindingsAccessor();
var optionsText = ko.utils.unwrapObservable(obj.optionsText);
var optionsValue = ko.utils.unwrapObservable(obj.optionsValue);
var sourceUrl = ko.utils.unwrapObservable(obj.sourceUrl); …
Run Code Online (Sandbox Code Playgroud) javascript jquery asp.net-web-api knockout.js jquery-select2
我遇到了一些问题$q.defer();
当我使用回调时,我的代码正在运行(视图已更新),但$q.defer();
事实并非如此.
这是我的代码:
服务:
eventsApp.factory('eventData', function($http, $q) {
return {
getEvent: function(callback) {
var deferred = $q.defer();
$http({method: 'GET', url: '/node/nodejsserver/server.js'}).
success(function(data, status, headers, config){
//callback(data.event);
deferred.resolve(data.event);
console.log('status: ', status, ' data: ', data);
}).
error(function(data, status, headers, config){
deferred.reject(status);
console.log('status: ', status);
});
return deferred.promise;
}
};
});
Run Code Online (Sandbox Code Playgroud)
控制器:
eventsApp.controller('EventController',
function EventController($scope, eventData) {
$scope.event = eventData.getEvent();
}
);
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
然后我找到了这个答案,我更新了我的控制器,如下所示:
eventsApp.controller('EventController',
function EventController($scope, eventData) {
eventData.getEvent().then(function(result) { …
Run Code Online (Sandbox Code Playgroud) 我正在使用 knockout.js 和select2插件。
\n我试图根据可观察值更改 select2 ajax url。
\n例如,如果基于某些选择,我会对 1 个 url 或另一个进行 ajax 调用。\n这里是示例代码:
<input type="hidden" data-bind="combobox: { optionsText: \'Name\', optionsValue: \'ID\', optionsCaption: \'\xd0\x98\xd0\xb7\xd0\xb1\xd0\xb5\xd1\x80\xd0\xb8...\', sourceUrl: partnerUrl }, value: ApplyToSubject" id="ApplyToSubject" name="ApplyToSubject">\n
Run Code Online (Sandbox Code Playgroud)\n这是检索 sourceUrl:partnerUrl 的方式:
\nself.partnerUrl = ko.computed(function () {\n var value = "";\n if (something)\n {\n value = apiUrls.customer;\n }\n else if (something else)\n {\n value = apiUrls.vendor;\n }\n else if(or another thing)\n {\n value = apiUrls.employee;\n }\n return value;\n });\n
Run Code Online (Sandbox Code Playgroud)\n我使用自定义绑定。\n以下是它的代码:
\n// …
Run Code Online (Sandbox Code Playgroud) 我遇到了一个奇怪的问题.
我使用MVC(而不是web api),因此控制器继承自Controller,而不是ApiController.
我用ajax调用控制器动作(POST),动作返回HttpResponseMessage
这是我得到的回应:
{"readyState":4,"responseText":"StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StringContent, Headers:\r\n{\r\n Location: /\r\n Content-Type: application/json; charset=utf-8\r\n}","status":200,"statusText":"OK"}
Run Code Online (Sandbox Code Playgroud)
但是,当ajax接收数据时,它会触发fail方法.
这是ajax函数:
$.ajax({
url: "someurl",
type: "post",
data: data,
dataType: "json",
contentType: "application/json; charset=utf-8"
}).done(function (data) {
alert(data.responseText);
window.location.href = "redirect to some url";
}).fail(function (data) {
alert("error");<-- this one is called even when i set HttpStatusCode.OK
alert(JSON.stringify(data));
}).always(function () {
});
Run Code Online (Sandbox Code Playgroud)
这是一个简化的控制器动作:
[HttpPost]
[AllowAnonymous]
public HttpResponseMessage Index(HttpRequestMessage request, Login model)
//public HttpResponseMessage Index(Login …
Run Code Online (Sandbox Code Playgroud) 看看这个小提琴
我试图将div #popup
放在页面的底部,重叠任何以前的内容和
#content
)我不确定,但我认为position: absolute
在这种情况下不起作用,至少不是我实现它的方式.
我该怎么办?
javascript ×3
jquery ×3
asp.net-mvc ×2
knockout.js ×2
angularjs ×1
css ×1
html ×1
html-helper ×1
httpresponse ×1
json ×1
promise ×1
razor ×1
web-config ×1