安装配置文件1.1后,在用户内容类型中添加至少一个字段,然后转到用户模块并单击添加新用户,单击保存,您将收到此错误.任何帮助都会很感激.
无法创建接口的实例.描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.
Exception Details: System.MissingMethodException: Cannot create an instance of an interface.
Source Error:
Line 146: public void EndProcessRequest(IAsyncResult result) {
Line 147: try {
Line 148: _httpAsyncHandler.EndProcessRequest(result);
Line 149: }
Line 150: finally {
Source File: C:\Users\rspaulino\Desktop\src\Orchard\Mvc\Routes\ShellRoute.cs Line: 148
Stack Trace:
[MissingMethodException: Cannot create an instance of an interface.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +98
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) …Run Code Online (Sandbox Code Playgroud) 你知道我可以轻松地将字符串数组的内容绑定到MVC Razor视图中的DropDownList吗?
public static string[] AgeRagne = new string[] { "Sun", "Mon", "Tues", "Wed" };
Run Code Online (Sandbox Code Playgroud)
更新:下面的代码工作.
@Html.DropDownListFor(
model => model.Filter.AgeRange,
new SelectList(Extensions.AgeRange, Model.Filter.AgeRange),
new { @class = "search-dropdown", name = "ageRange" }
)
Run Code Online (Sandbox Code Playgroud) 该参数string[] orderTypeNames将为null.
mvc行动
public PartialViewResult EditMultipleOrderStates(
string[] orderTypeNames,
int[] orderIds)
Run Code Online (Sandbox Code Playgroud)
JavaScript的
$('#edit-mulitple-order-states-button').click(function () {
ids = [];
types = [];
$checked = $('.order-queue-order input:checked');
$orders = $checked.closest('.order-queue-order');
$orders.each(function (index, elem) {
$order = $(elem);
ids.push($order.attr("orderId"));
types.push($order.attr("orderType"));
});
data = {
orderIds: ids,
orderTypeNames: types
};
$.post('EditMultipleOrderStates', data, function (response) {
//...
});
});
Run Code Online (Sandbox Code Playgroud)
小提琴手

orderIds%5B%5D=97&orderIds%5B%5D=98&orderIds%5B%5D=93&orderTypeNames%5B%5D=DeliveryOrder&orderTypeNames%5B%5D=DeliveryOrder&orderTypeNames%5B%5D=DeliveryOrder
Run Code Online (Sandbox Code Playgroud)
是方括号导致问题吗?我怎样才能绑定到这些数组?
编辑:我在同一时间手动构建查询字符串.
query = "";
for each...
query += "orderIds=" + $order.attr("orderId") + "&";
query += "orderTypeNames=" + $order.attr("orderType") + "&";
Run Code Online (Sandbox Code Playgroud) 你能在Nancy有多个自定义模型绑定器吗?我需要绑定来自datatables jQuery插件的服务器端处理请求,这不适合我们当前的"mvc样式"自定义模型绑定器.特别是关于列表,数据表将它们表示为mylist_0,mylist_1等而不是mylist [0],mylist [1].
那么我可以添加另一个模型绑定器来处理这些不同的列表样式,如果我这样做,南希怎么知道使用哪一个?
在MVC 3中,我通过创建一个实现的新类来创建自定义模型绑定器Systen.Web.Mvc.IModelBinder,然后在内部Global.asax.cs和内部Application_Start()使用注册ModelBinders.Binders.Add(typeof(sometype), new MyModelBinder());
在MVC 4中,我理解您应该使用它System.Web.Http.ModelBinding.IModelBinder来实现模型绑定器.
所以我有两个问题:
为什么我们应该使用模型绑定器System.Web.Http.ModelBinding而不是来自Systen.Web.Mvc?我没有看到它在任何地方被列为已弃用,那么旧版本的问题是什么?
如果我从中实现我的模型绑定器System.Web.Http.ModelBinding.IModelBinder,如何在我的应用程序中注册它以便实际使用它?
我有一个webApi2项目和另一个项目,其中我有我的Model类和BaseModel,它是所有模型的基础,如下所示,
public class BaseModel
{
public string UserId { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
所有其他模型都是从我的BaseModel派生的.
在webapi我有我的CustomerController如下,
public class CustomerController : ApiController
{
[HttpPost]
public GetCustomerResponseModel Get(GetCustomerRequestModel requestModel)
{
var response = new GetCustomerResponseModel();
//I need only the UserId coming from the BaseModel is binded from request headers
var userId = requestModel.UserId;
//I want all model data except UserId is binded with default model binding
var customerData = requestModel.CustomerData;
var someOtherData = requestModel.SomeOtherData;
return response;
}
[HttpPost]
public AddStockAlertResponseModel AddStockAlert(AddStockAlertRequestModel requestModel)
{ …Run Code Online (Sandbox Code Playgroud) model-binding parameterbinding custom-model-binder asp.net-web-api asp.net-web-api2
我无法想出一个最好用口头和一些代码描述的问题的解决方案.我正在使用VS 2013,MVC 5和EF6代码优先; 我还使用MvcControllerWithContext脚手架,它生成一个支持CRUD操作的控制器和视图.
简单地说,我有一个包含CreatedDate值的简单模型:
public class WarrantyModel
{
[Key]
public int Id { get; set; }
public string Description { get; set; }
DateTime CreatedDate { get; set; }
DateTime LastModifiedDate { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
包含的MVC脚手架为其索引,创建,删除,详细信息和编辑视图使用相同的模型.我想在'创建'视图中创建CreatedDate; 我不希望它在"编辑"视图中,因为我不希望在编辑视图发回服务器时更改其值,并且我不希望任何人在表单发布期间能够篡改该值.
理想情况下,我不希望CreatedDate进入"编辑"视图.我已经在模型的CreatedDate属性上找到了一些属性(例如,[ScaffoldColumn(false)]),这些属性阻止它出现在Edit视图中,但随后我在回发时遇到绑定错误,因为CreatedDate结束了值为1/1/0001 12:00:00 AM.这是因为编辑视图没有将值传回给CreatedDate字段的控制器.
我不想实现需要任何SQL Server更改的解决方案,例如在包含CreatedDate值的表上添加触发器.如果我想进行快速修复,我会在呈现编辑视图之前存储CreatedDate(服务器端),然后在回发时恢复CreatedDate - 这样我就可以更改1/1/0001日期在渲染视图之前从数据库中提取到CreatedDate EF6.这样,我可以将CreatedDate作为隐藏的表单字段发送,然后在回发后覆盖控制器中的值,但我没有一个很好的策略来存储服务器端值(我不想使用Session变量或者ViewBag).
我看着使用[Bind(Exclude ="CreatedDate")],但这没有帮助.
我的控制器的编辑回发函数中的代码如下所示:
public ActionResult Edit([Bind(Include="Id,Description,CreatedDate,LastModifiedDate")] WarrantyModel warrantymodel)
{
if (ModelState.IsValid)
{
db.Entry(warrantymodel).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(warrantymodel);
}
Run Code Online (Sandbox Code Playgroud)
我以为我可能能够检查if上面的块中的db.Entry(warrantymodel)对象并在OriginalValue中检查CreatedDate,但是当我尝试访问该值时(如下所示),我得到类型'System'的异常.InvalidOperationException":
var originalCreatedDate = db.Entry(warrantymodel).Property("CreatedDate").OriginalValue; …Run Code Online (Sandbox Code Playgroud) 我从文章中编写代码,并且有:
public IActionResult Create([Bind(Include="Imie,Nazwisko,Stanowisko,Wiek")] Pracownik pracownik)
{
blablablab
}
Run Code Online (Sandbox Code Playgroud)
我想编译,但它显示错误.
include is not a valid named attribute argument.
Run Code Online (Sandbox Code Playgroud)
但在互联网上我看到了类似于我的代码的代码.有人向我解释发生了什么事吗?当然,我使用的是asp.net 5.
我试图构建一个ASP.NET Core 1.1 Controller方法来处理如下所示的HTTP请求:
POST https://localhost/api/data/upload HTTP/1.1
Content-Type: multipart/form-data; boundary=--------------------------625450203542273177701444
Host: localhost
Content-Length: 474
----------------------------625450203542273177701444
Content-Disposition: form-data; name="file"; filename="myfile.txt"
Content-Type: text/plain
<< Contents of my file >>
----------------------------625450203542273177701444
Content-Disposition: form-data; name="text"
Content-Type: application/json
{"md5":"595f44fec1e92a71d3e9e77456ba80d0","sessionIds":["123","abc"]}
----------------------------625450203542273177701444--
Run Code Online (Sandbox Code Playgroud)
这是一个multipart/form-data请求,一部分是(小)文件,另一部分是基于提供的规范的json blob。
理想情况下,我希望控制器方法如下所示:
POST https://localhost/api/data/upload HTTP/1.1
Content-Type: multipart/form-data; boundary=--------------------------625450203542273177701444
Host: localhost
Content-Length: 474
----------------------------625450203542273177701444
Content-Disposition: form-data; name="file"; filename="myfile.txt"
Content-Type: text/plain
<< Contents of my file >>
----------------------------625450203542273177701444
Content-Disposition: form-data; name="text"
Content-Type: application/json
{"md5":"595f44fec1e92a71d3e9e77456ba80d0","sessionIds":["123","abc"]}
----------------------------625450203542273177701444--
Run Code Online (Sandbox Code Playgroud)
但是,a,这不仅仅适用于{TM}。当我有这样的东西时,IFormFile 确实会填充,但是json字符串不会反序列化为其他属性。
我还尝试向其中添加除以外的所有属性的Text属性UploadPayload,该属性 …
在我们的ASP.net Core Web API应用程序中,当我的控制器方法接受将ENUMs反序列化为字符串的ENUM属性的复杂对象时,我正在寻找一种捕获绑定错误的方法。
例如。
class Person
{
public string Name {get; set;}
public SexEnum Sex {get; set;}
}
enum SexEnum
{
Male,
Female
}
Run Code Online (Sandbox Code Playgroud)
我们使用整个系统,StringEnumConverter因此JSON序列化实例Person如下所示:
{
"name": "Ann",
"sex": "female"
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我发布此JSON(请注意sex属性中的错字):
{
"name": "Ann",
"sex": "femal"
}
Run Code Online (Sandbox Code Playgroud)
由于绑定失败,控制器方法接收到的整个对象为NULL。
我想捕获该绑定错误,而不是让管道像没有什么错误一样进入控制器,而是向客户端返回一个BAD REQUEST,其中包括未能绑定哪个属性值的详细信息。
我知道我要反序列化的类型,我知道我要反序列化的属性类型,我可以看到该值未解析为该类型。因此,我认为必须有一种方法可以将详细信息提供给客户。我只是不知道在哪里以及如何插入它。
我希望该解决方案在整个系统范围内,以便涵盖所有枚举,而不必将属性放在模型的属性或枚举本身上。(这是因为我们将API模型作为nuget包分发,不能有任何依赖关系。)
model-binding ×10
asp.net-mvc ×4
asp.net-core ×3
asp.net ×1
attributes ×1
c# ×1
enums ×1
javascript ×1
jquery ×1
nancy ×1
orchardcms ×1
razor ×1
scaffold ×1