【发布时间】:2020-04-09 00:19:30
【问题描述】:
我正在使用自己的数据库,我想从我的数据库中获取描述并将数据放入 html 中的表中。 但是我真的找不到任何有用的东西,而且我真的不知道如何将数据从控制器传输到视图 - 或者如何将数据从视图请求到控制器。
这就是我的控制器的样子:
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Test.Models;
namespace Test.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
public IActionResult getTableNames()
{
DatabaseItemDescription databaseItemDescription = new DatabaseItemDescription();
databaseItemDescription.Name = "abc";
databaseItemDescription.Description = "def";
databaseItemDescription.Content = "ghi";
return View(databaseItemDescription); //Does this work?
}
}
}
这就是我的 Index.cshtml 的样子:
@page
@model DatabaseItemDescription
<h1>DatabaseEditTest</h1>
<table id="buttonTable">
<thead>
</thead>
</table>
<table id="descriptionTable"
class="table table-bordered table-condensed table-striped">
<thead>
<tr>
<th>Action</th>
<th>Name</th>
<th>Description</th>
<th>Content</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script>
function getFirstTableDesc() {
$("#firstTable thead").remove();
$("#buttonTable thead").append("<tr>" + "<th><button onclick='updateTableDesc()'>Update</button></td>" + "<th><button onclick='refreshTableDesc()'>Refresh</button></td>" + "<tr>");
}
function updateTableDesc() {
$("#descriptionTable tbody").empty();
//here i want to read the Data from the Controller and insert it into the table like:
//Fetch Data from Controller
//$("#descriptionTable tbody").append("<tr>" + "<td><button onclick='Edit()'>Edit</button></td>" + "<td>${Name}</td>" + "<td>${Description}</td>" + "<td>${Content}</td>" + "</tr>");
}
}
function refreshTableDesc() {
}
</script>
如果有人可以帮助我,我将非常感激! 谢谢
【问题讨论】:
标签: asp.net-mvc asp.net-core model-view-controller razor controller