0
我有一個有屬性的模型。而且,我想檢查是否有任何模型項目有一些值。也沒有屬性被設置爲強制或可選的使用數據註釋。如果沒有屬性被分配,並且任何值那麼我應該設置一些模型誤差,例如「請指定一些搜索條件。」如何檢查是否有任何模型項目在MVC中分配了值?
@using (Html.BeginForm("GetAdvanceSearchData", "Home", FormMethod.Post)){
<div class="rTableCell" style="border:none !important">
@Html.TextBoxFor(m => m.MessageStatus, new { placeholder = Html.DisplayNameFor(n => n.MessageStatus), @class = "fieldtextbox", @style = "height: 25px !important" })
@Html.ValidationMessageFor(m => m.MessageStatus)
</div>
<div class="rTableCell" style="border:none !important">
@Html.TextBoxFor(m => m.RequestType, new { placeholder = Html.DisplayNameFor(n => n.RequestType), @class = "fieldtextbox", @style = "height: 25px !important" })
@Html.ValidationMessageFor(m => m.RequestType)
</div>
<div class="rTableCell" style="border:none !important">
</div>
<div class="rTableCell" style="border:none !important">
<p class="submit">
<button type="submit" name="submit">
<i class="fa fa-arrow-right" aria-hidden="true"></i>
</button>
</p>
</div>
}
這些只是針對模型幾個屬性。
請將您的代碼和[MCVE]這個問題。 – Esko
你想做它的客戶端或服務器端? –