c# - Asp.net core View 组件模型绑定(bind)

标签 c# asp.net-core-mvc

我正在寻找一种在 View 组件中调用 Model binder 的方法。我更喜欢使用来自 asp.net core 的内置功能,但这仅在 Controller 内部可用,而不是 View Components 本身。有什么办法可以解决这个问题?

最佳答案

根据 View Components文档:

View Components don’t use model binding, and only depend on the data you provide when calling into it.


但是,您可以将模型作为对象/参数传递到您的 ViewComponent 中:

@await Component.InvokeAsync("PriorityList", MyModel)

@await Component.InvokeAsync("PriorityList", new { maxPriority = 2, isDone = false })


你想达到什么目的?

关于c# - Asp.net core View 组件模型绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36622098/

相关文章:

c# - 使用 Azure AD 的用户管理器

c# - 当父任务抛出异常时停止继续任务

c# - 将 WPF 中的对象序列化为 XML

c# - 传递上下文信息

.net-core - 是否已在ASP.NET Core MVC 2.1中替换了bundleconfig.json?

asp.net-core - 如何在 IIS 上部署 MVC 6 应用程序而不发布

c# - 如何在 catch block 中从 Assert.Multiple 获取所有已保存的结果?

c# - GMap .net 离线

asp.net-core-mvc - 在类库中访问 appsettings.json

asp.net-core - ASP.Net Core RC1 : System. ArgumentException:路径中存在非法字符