他のモデルを組み込んだモデルを使用しているときに多くの問題 (検証、シリアル化) が発生しており、以前にこのような問題が発生したことがあるかどうかを知りたいと思っていました。たとえば、次のモデルが添付された問い合わせフォームがあります。
モデル
namespace
{
public class EnquiryStudent
{
public enquiry enquiry { get; set; }
public student student { get; set; }
}
}
Inquiry および Student モデル (Inquiry Student 内に組み込まれている) は、データベースから自動生成されます (私はデータベース ファースト アプローチを使用しています)。
たとえば、ここで発生する問題は、ビューを使用して上記のモデルに基づくフォームを表示することです。
意見
@using (@Html.BeginForm())
{
<div>
<fieldset>
<fieldset>
<legend>Enquiry</legend>
<div class="editor-label">
@Html.LabelFor(m => m.student.firstname)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.student.firstname)
@Html.ValidationMessageFor(m => m.student.firstname)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.student.surname)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.student.surname)
@Html.ValidationMessageFor(m => m.student.surname)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.student.email)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.student.email)
@Html.ValidationMessageFor(m => m.student.email)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.enquiry.subject)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.enquiry.subject)
@Html.ValidationMessageFor(m => m.enquiry.subject)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.enquiry.enquiry_text)
</div>
<div class="editor-field">
@Html.TextAreaFor(m => m.enquiry.enquiry_text)
@Html.ValidationMessageFor(m => m.enquiry.enquiry_text)
</div>
</fieldset>
<p>
<input type="submit" class="rounded-button-gray-shades" value="Send" />
</p>
</fieldset>
</div>
}
クライアント側の検証は、照会テキスト (EnquiryStudent モデル内に埋め込まれた照会の属性、つまり、このクライアント側のみサーバー側を検証しませんか??
enquiry_text を TextAreaFor ではなく TextBoxFor に変更すると、さらに奇妙になります。または、EnquiryStudent モデル (別のモデルに埋め込まれていない) にダミー フィールドを追加して、別のエンティティのテキスト領域を作成すると、正常に動作します。
私が言ったように、誰かが光を当ててくれませんか.
ありがとう、