0
@using (Html.BeginForm())
{
<p>
Search By: @Html.TextBox("SearchString")
@Html.RadioButton("searchByOption", "Load Id")<text>Load Id</text>
@Html.RadioButton("searchByOption", "User Id")<text>User Id</text>
<input type="submit" value="Search" />
</p>
}
ビューを実行する前に、index.cshtmlファイルのテキストボックスの内容を検証したいと思います。テキストボックスが空白で、検索ボタンを押した場合、「検索する前にテキストボックスに値を入力してください」というメッセージで簡単に返信できますか?それが表示するようにValidationMessageFor
ヘルパーを使用して、モデルを指定し、TextBoxFor
を使用するビューで今テキストボックスの内容を確認する
public namespace YourNamespace.Models
public class SearchModel
{
[Required(ErrorMessage = "Enter a value in the textbox prior to searching")]
public string Term
// other properties here
}
}
:
ありがとう、これは非常に役に立ちます! – DiaGea