因此,我试图发布包含一些数据的表单,但是由于某些原因,当单击发布数据的按钮时,我没有得到任何服务器支持,所有值均为NULL。
如您所见,这是一个使用剃刀的简单表单,我已经设置了要发送的元素的名称和id属性
<table class="table table-hover mb-0">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Version</th>
</tr>
</thead>
<tbody>
@foreach (var _model in Model)
{
<tr>
@using (Html.BeginForm("Start", "Dashboard", FormMethod.Post))
{
<div class="form-group">
<td id="serverid" name="serverid">@Html.DisplayTextFor(x => _model.ServerID) @Html.HiddenFor(x => _model.ServerID)</td>
<td>
@Html.DisplayTextFor(x => _model.ServerName) @Html.HiddenFor(x => _model.ServerName)
</td>
<td>
@Html.DisplayTextFor(x => _model.Version) @Html.HiddenFor(x => _model.Version)
</td>
<td>
<button type="submit" asp-action="Start" asp-controller="Dashboard" class="btn btn-icon waves-effect waves-light btn-success" onclick="Start('@_model.ServerName')"> <i class="fa fa-power-off"></i> </button>
</td>
</div>
}
</tr>
}
</tbody>
</table>
这是模型的样子
public class ServerModel
{
public string ServerID { get; set; }
public string ServerName { get; set; }
}
这是控制器内部的动作
//The "model" parameter here exists, but all the properties are null when inspecting it
public async Task<IActionResult> Start(ServerModel model)
{
//Doing stuff here
}
发布后检查模型时,为什么模型中的所有属性都为空?我正在检查断点。
答案 0 :(得分:0)
将您的提交按钮更改为-
from bokeh.io import curdoc
from bokeh.layouts import row, column
import pandas as pd
from bokeh.models import ColumnDataSource, ColorBar, DataTable, DateFormatter, TableColumn, HoverTool, Spacer, DatetimeTickFormatter
#Pandas
df = pd.DataFrame(data = {'Apples': [5,10], 'Bananas': [16,15], 'Oranges': [6,4]})
df.rename(index={0:'A',1:'B'}, inplace=True)
#BOKEH
sourceTableSummary = ColumnDataSource(df)
Columns = [TableColumn(field=colIndex, title=colIndex) for colIndex in df.columns]
data_table = DataTable(columns=Columns, source=sourceTableSummary, index_position = 0, width = 1900, height = 200, fit_columns=False)
#Funcs
def return_value(attr, old, new):
print('return_value')
selectionRowIndex=sourceTableSummary.selected.indices[0]
print("Selected Row Index ", str(selectionRowIndex))
selectionValue=sourceTableSummary.data['Apples'][selectionRowIndex]
print("Selected value for Apples ", str(selectionValue))
# selectionColumnIndex?
# selectionRowHeader?
# selectionColumnHeader?
sourceTableSummary.on_change('selected', return_value)
curdoc().add_root(column(children=[data_table]))
由于您位于form元素(由beginform生成)中,因此不需要其他属性。也不完全确定您的意图是什么-
<button type="submit" class="btn btn-icon waves-effect waves-light btn-success"> <i class="fa fa-power-off"></i> </button>
答案 1 :(得分:0)
首先,由于要通过Form Post传递数据,因此您可以删除onclick="Start('@_model.ServerName')"
提交按钮,然后修改以下代码:
@Html.HiddenFor(x => _model.ServerID)
@Html.HiddenFor(x => _model.ServerName)
收件人:
<input name="ServerID" type="hidden" value="@_model.ServerID">
<input name="ServerName" type="hidden" value="@_model.ServerName">
因此它将在模型绑定期间将名称与模型的属性名称匹配。