c# - 是否有任何其他方式访问 HTML:Textboxfor 动作控制器中的内部视图?
问题描述
我从 URL 读取 JSON 并在 MVC 视图 DotnetCore 中显示为表格格式。我在表单控件下的同一视图中有 @Html.TextBoxFor 控件。
为了以表格格式显示,我在视图中同时使用了注册 @model 和 using 语句。所以我无法在控制器操作方法中访问 @Html.TextBoxFor 值。是否有任何访问 HTML:Textboxfor 在操作控制器中的视图内的方式?
@model System.Data.DataTable
@using System.Data;
无法注册 namespace.models.model
@using (Html.BeginForm("Index", "Admin", FormMethod.Post))
需要在控制之下访问
{ @Html.TextBoxFor(s => s.ImportJsonUrlName, new { id = "PickUrlID", style = "width:800px" })
点击按钮
<input type="submit" value="Import JSON" />
以表格形式显示
<table class="table table-bordered table-dark">
<thead>
<tr>
@foreach (DataColumn col in Model.Columns)
{
<th>@col.ColumnName</th>
}
</tr>
</thead>
<tbody>
@foreach (DataRow row in Model.Rows)
{
<tr>
@foreach (DataColumn col in Model.Columns)
{
<td>@row[col.ColumnName]</td>
}
</tr>
}
</tbody>
</table>
控制器代码:
[HttpPost]
public IActionResult Index(AdminModel model)
{
DataTable dt = new DataTable();
string json = (new WebClient()).DownloadString("https://raw.githubusercontent.com/wedeploy-examples/supermarket-web-example/master/products.json");
dt = JsonConvert.DeserializeObject<DataTable>(json);
return View(dt);
}
解决方案
推荐阅读
- php - 如何使用来自 daabase 的 jquery ajax 获取 html 表单字段的数据
- c - 创建一个填充随机唯一数字的数组
- firebase - 使用 FirebaseAuth 、 Firestore 和 Google 登录的 Flutter multidex 问题
- ios - 为什么默认情况下 Swift 中的属性是非原子的?
- javascript - 如何将多个子项链接到单个父项?
- reactjs - GQL 不会自动调用查询
- html - 在 div 上应用灰度,除了它的子元素之一
- laravel - 每次递增按钮单击后如何存储用户ID
- c# - 编译时的 C# 代码扩展/注入
- c++ - 尝试从 Visual Studios C++ 中的加密字符串输出解密字符串时出现逻辑错误