c# - 在 View 组件ASP.NET Core 1.0中使用表单

标签 c# razor asp.net-core asp.net-core-viewcomponent

我有 View 组件1:

<form class="form-horizontal">
    <input type="text" name="ip1" class="form-control"/>
    <input type="submit" name="btnSubmit" class="btn btn-default" />
</form>

并查看组件2:

<form class="form-horizontal">
    <input type="text" name="ip1" class="form-control"/>
    <input type="submit" name="btnSubmit" class="btn btn-default" />
</form>

两个 View 组件位于同一页面中。但我不知道如何处理每个 View 组件内的发布请求。以及如何将模型发布到 View 组件? 后面的示例代码或类似代码:

 public class Component1ViewComponent : ViewComponent
 {
    public Component1ViewComponent()
    {

    }

    public async Task<IViewComponentResult> InvokeAsync(bool isPost)
    {
        if (isPost)
        {
            //handle post request and get model value here
        } else
        {

        }
        return View(model);
    }
}

最佳答案

ViewComponents不是 http 请求端点,因此您尝试执行的操作是不可能的。仅当生成 View 时, View 组件才会出现。

关于c# - 在 View 组件ASP.NET Core 1.0中使用表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38283207/

相关文章:

c# - MVC - 从枚举中排除

msbuild - 在构建服务器上使用 ASP.NET Core 项目构建解决方案

c# - 数学解释为什么 Decimal 到 Double 的转换被破坏并且 Decimal.GetHashCode 分隔相等的实例

c# - 在 C# 中使用 Clay 构建转储对象

c# - 了解Unity的GameObject.Find()、GetComponent()和对象回收

c# - IHostedService 的多种实现

asp.net-core - 将visual studio升级到16.10.0后拒绝加载_framework/aspnetcore-browser-refresh.js

c# - 如何从其 valueMember 设置组合框基的选定索引? (C# 窗口窗体)

c# - 字段的 ASP.NET MVC 内联帮助程序

asp.net-mvc - Jquery 编写 if 条件的更好方法