.Net Core Razor引擎 Form复杂模型绑定

复杂模型的绑定

razor view

 <form id='shenlaifusubmit' asp-action="SaveMerchantChannel" method="post">
            <div class="form-group">
                <label for="pay_memberid">Merchant Id</label>
                <input type='text' asp-for="@Model.MerchantPaymentRequest.MerchantId" class="form-control" />
            </div>
            <div class="form-group">
                <label for="pay_memberid">Channel Code</label>
                <input id="channel_code" type='text' asp-for="@Model.MerchantPaymentRequest.PayChannelCode" class="form-control" placeholder="请选择Channel" />
            </div>
            <div class="form-group">
                <label>Pay Memberid</label>
                <input type='text' asp-for="@Model.MerchantPaymentRequest.PayMemberId" class="form-control" id='pay_memberid' />
            </div>
            <div class="form-group">
                <label for="exampleInputPassword1">PayBankcode</label>
                <input type='text' asp-for="@Model.MerchantPaymentRequest.PayBankcode" class="form-control" id='pay_bankcode' />
            </div>
            <div class="form-group">
                <label for="exampleInputPassword1">PayNotifyurl</label>
                <input type='text' asp-for="@Model.MerchantPaymentRequest.PayNotifyurl" class="form-control" id='pay_notifyurl' />
            </div>
            <button class="btn btn-outline-primary" type="submit">提交</button>
        </form>

model

    [BindProperties(SupportsGet = true)]
    public class PaymentChannelModel
    {
        public List<PaymentChannel> PaymentChannel { get; set; }
        [BindProperty]
        public MerchantPaymentRequest MerchantPaymentRequest { get; set; }
    }

总结

需要使用特性进行声明

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在ASP.NET Core Razor编程中,列表模板页面是非常常见的。这些页面通常用于显示数据库或其他数据源中的一组记录。 在本文中,我将向您展示如何使用ASP.NET Core Razor列表模板页面。 首先,我们需要创建一个模型类来代表我们的数据。例如,假设我们正在构建一个博客应用程序,我们需要一个名为“Post”的模型类来表示博客文章。以下是一个示例模型类: ```csharp public class Post { public int Id { get; set; } public string Title { get; set; } public string Content { get; set; } public DateTime CreatedDate { get; set; } } ``` 接下来,我们需要创建一个控制器类来处理与“Post”模型类相关的操作。以下是一个示例控制器类: ```csharp public class PostController : Controller { private readonly ApplicationDbContext _context; public PostController(ApplicationDbContext context) { _context = context; } public IActionResult Index() { var posts = _context.Posts.ToList(); return View(posts); } } ``` 在此示例控制器中,我们从数据库中检索所有博客文章,并将它们传递给视图。 现在,我们需要创建一个视图来显示我们的博客文章列表。我们可以使用ASP.NET Core Razor模板引擎来创建一个动态模板,该模板可以将我们的博客文章显示为HTML表格。以下是一个示例视图: ```html @model IEnumerable<Post> <table> <thead> <tr> <th>Title</th> <th>Content</th> <th>Created Date</th> </tr> </thead> <tbody> @foreach (var post in Model) { <tr> <td>@post.Title</td> <td>@post.Content</td> <td>@post.CreatedDate.ToShortDateString()</td> </tr> } </tbody> </table> ``` 在此示例视图中,我们使用了一个foreach循环遍历我们的博客文章,并将它们显示为HTML表格行。 最后,我们需要在控制器的Index方法中返回视图。在我们的示例控制器中,我们已经传递了一个包含所有博客文章的IEnumerable<Post>对象。我们可以将此对象传递给视图,如下所示: ```csharp public IActionResult Index() { var posts = _context.Posts.ToList(); return View(posts); } ``` 现在,当我们访问PostController的Index操作时,我们将看到一个包含所有博客文章的HTML表格。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值