問題私は1つの隠しフィールドを持つフォームを持っており、送信ボタンをカスタム列とのWebGridを使用していますWebGridの列が通らない非表示フィールド
。 HTMLソースを見ると、隠しフィールドに値があることがわかります。フォームはコントローラ内で正しいHttpPostメソッドを送信し、ヒットします。問題は、隠されたフィールドが投稿と一緒に行かないことです。ここ
コード
はWebGridのを生成するコードは、次のとおり
WebGrid wgSearchResults = new WebGrid(
source: Model.notes,
rowsPerPage: 10,
canPage: true,
canSort: true
);
wgSearchResults.Pager(WebGridPagerModes.All, numericLinksCount: 10);
@wgSearchResults.GetHtml(
htmlAttributes: new { id = "wgSearchResults" },
mode: WebGridPagerModes.All,
columns: wgSearchResults.Columns(
wgSearchResults.Column(format: (item) =>
{
System.Text.StringBuilder html = new System.Text.StringBuilder();
html.Append("<form action='/ManageData/ViewFacilities' method='post'>");
html.Append("<input type='hidden' id='hidBusinessId_' value='" + item.businessId.ToString() + "' />");
html.Append("<input type='submit' id='btnViewFacilities_" + item.ID.ToString() + "' name='btnSubmit_" + item.ID.ToString() + "' value='View Facilities' />");
html.Append("</form>");
return new HtmlString(html.ToString());
},
canSort: false
),
wgSearchResults.Column(columnName: "note", header: Sorter("note", "Note", wgSearchResults), canSort: true)
)
)
Model.notes構造は、このクラスのインスタンスのリストである:
public class SearchNotesResult
{
public int ID { get; set;}
public int businessId { get; set; }
public string note { get; set; }
}
コントローラこのボタンがヒットするメソッド:
[HttpPost]
public ActionResult ViewFacilities(string hidBusinessId)
{
int businessId = 0;
bool isValidNumber = false;
isValidNumber = int.TryParse(hidBusinessId, out businessId);
if (isValidNumber)
{
if (businessId > 0)
{
TempData["BusinessId"] = businessId;
return RedirectToAction("GoHere");
}
else
return RedirectToAction("DontGoHere");
}
else
{
return RedirectToAction("DontGoHere");
}
}
上記の方法では、hidBusinessIdの値はnullです。
試み
- は、カミソリの構文(
<text>
タグ付き@
)を使用してこのコラムを再構築 - (のみ送信ボタンを含まれている)上記のメソッドにパラメータ
FormCollection form
を追加します。運がない。 - 数時間の研究。それが私がここにいる理由です。
ボタンIDにビジネスIDを追加し、
Html.ActionLink
などの異なる制御)を変更するオプション
- 提案する
ありがとうございました!
あなたは隠された入力に 'name'属性がないので、投稿するものは何もありません(無効な' id'属性を削除し、 'name = 'hidBusinessId''を使います)。また、送信ボタンから無意味な 'id'属性と' name'属性を削除することもできます。そして 'int'からメソッドのパラメータは' string'ではなく 'int hidBusinessId'でなければなりません –