我有一个JS脚本:
$(document).ready(function () {
$('.z').on('click', function (event) {
event.preventDefault();
$.ajax({
url: "/DeviceUsage/Edit",
type: "POST",
contentType: "application/json; charset=utf-8",
headers: {
'RequestVerificationToken': '@TokenHeaderValue()'
},
data: JSON.stringify({
deviceusage: {
DeviceInstanceId: $('.a').children("#DeviceInstanceId").val(),
UserId: $('.a').children('#UserId').val(),
storageId: $('.a').children('#storageId').val()
}
}),
error: function (data) {
alert("wystąpił nieokreślony błąd " + data);
},
success: function (data) {
alert(data.newurl);
if (data.ok) {
$("#Modal").modal('hide');
window.location = data.newurl;
}
else {
$('.modal-body').html(data);
}
}
})
})
@functions{
public string TokenHeaderValue()
{
string cookieToken, formToken;
AntiForgery.GetTokens(null, out cookieToken, out formToken);
return cookieToken + ":" + formToken;
}
}
});
以及DeviceUsage控制器中的一种方法:
[HttpPost]
[AdminAuthorization]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include="StorageId,UserId,DeviceInstanceId")] DeviceUsage deviceusage)
{
if (deviceusage.UserId == 6 && deviceusage.StorageId==3)
{
ModelState.AddModelError("", "Zarezerwowane urządzenie nie moze byc przypisane do biurka");
}
if(deviceusage.UserId==1 && deviceusage.StorageId==3)
{
ModelState.AddModelError("", "Wolne urządzenie nie może przebywać na jakimś biurku");
}
if((deviceusage.UserId!=1 & deviceusage.UserId!=6)&deviceusage.StorageId!=3)
{
ModelState.AddModelError("", "Urzązenie przypisane do kogos nie moze przebywac w magazynie");
}
if (ModelState.IsValid)
{
unitOfWork.deviceUsageRepository.Update(deviceusage);
unitOfWork.Save();
return Json(new { ok = true, newurl = Url.Action("Index") });
}
ViewBag.DeviceInstanceId = new SelectList(unitOfWork.deviceInstanceRepository.Get(), "Id", "SerialNo", deviceusage.DeviceInstanceId);
ViewBag.StorageId = new SelectList(unitOfWork.storageRepository.Get(), "Id", "Name", deviceusage.StorageId);
var data = unitOfWork.userRepository.Get()
.Select(s => new
{
Id = s.Id,
Credentials = s.Name + " " + s.Surname
}
);
ViewBag.UserId = new SelectList(data, "Id", "Credentials", deviceusage.UserId);
return PartialView(deviceusage);
}
我试图在C#方法的开始处设置一个断点,但是它从未被击中,因此Error必须在其他地方。你能告诉我我做错了吗?
参考方案
我猜这两个属性中的任何一个都限制了对该函数的访问。
[AdminAuthorization]
[ValidateAntiForgeryToken]
删除并尝试一次。
如何从php中获取datatables jQuery插件的json数据 - php我是PHP的新手,正在尝试使用Datatables jQuery插件。我知道我必须从.php文件中获取数据,然后在数据表中使用它,但是我似乎无法通过ajax将其传递给数据表。我设法从数据库中获取数据,并对其进行json编码,但是后来我不知道如何在我的index.php文件中调用它,并在其中显示它。我究竟做错了什么?这是我的代码:HTML(已编辑): <…
如何在没有for循环的情况下在Javascript中使用Django模板标签 - javascript我想在JavaScript中使用模板变量:我的问题是在javascript代码中使用for循环,for循环之间的所有事情都会重复..但我不想要....下面粘贴了我的代码..有人可以告诉我更好的方法吗这..因为这看起来很丑..这是我的代码: {% block extra_javascript %} <script src="/static/js…
Mongo抛出“元素名称'名称'无效”异常 - c#我正在更新一个简单的字段。var filterDocument = new BsonDocument { { "name", "alice" } }; var newDocument = new BsonDocument { { "name", "Alice" } }; coll…
T-SQL等价的正则表达式'\ b' - c#我正在将利用regex的CLR函数转换为SQL函数。我知道SQL Server并不完全支持正则表达式,但是我只需要一种情况就可以搜索单词。搜索字段值:{"Id":1234, "Title": "The quick brown"}.NET中的正则表达式模式:'\b' + '…
如何在数据表中显示错误消息 - php我将Datatable用于我的候选人列表,并使用地区和政党名称搜索候选人。我为此使用ajax。问题是,当没有任何搜索结果时,我无法显示“未找到结果”。我该怎么做?码:单击搜索按钮时:$(document).on("click", "#submit_filter", function(){ $(this).attr(…