每次遠程確認火災的窗體上,我得到以下網址...不出我所料: http://localhost:13927/Validation/ValidateAnswer?%5B0%5D.Episodes%5B0%5D.Questions%5B0%5D.Answers%5B0%5D.AnswerText=undefined&%5B0%5D.Episodes%5B0%5D.Questions%5B0%5D.Answers%5B0%5D.Id=undefinedAsp.net MVC 3遠程驗證問題
控制器是正確的。該行動是正確的,但參數不是我所期望的。任何想法如何我可以糾正這一點?爲驗證動作的簽名是public JsonResult ValidateAnswer(string answerText, int id).
這裏是型號:
public class Answer
{
public int Id { get; set; }
[Required(ErrorMessage = "Please enter an answer.")]
[Remote("ValidateAnswer", "Validation", AdditionalFields = "Id")]
public string AnswerText { get; set; }
}
這裏是頁:
@using (Html.BeginForm("/", "Home", FormMethod.Post, new {id="frm"}))
{
for (var p = 0; p < Model.Count; p++)
{
<div class="hidden questions" id="@Model[p].Id">
@for (var i = 0; i < Model[p].Episodes.Count; i++)
{
<div class="even" style="margin-top: 15px; padding: 15px;">
@Html.EditorFor(model => model[p].Episodes[i])
</div>
}
</div>
}
}
下面是引用編輯:
<h3 style="margin: 0; margin-bottom: 15px;">@Model.EpisodeType, which started on @Model.StartDate and ended on @Model.EndDate</h3>
@Html.HiddenFor(model=>model.Id)
@for (var i = 0; i < Model.Questions.Count; i++)
{
<p style="margin: 0; margin-bottom: 5px;">
<span style="font-weight: bold; font-size: 1.1em">@Model.Questions[i].QuestionText</span><br/>
</p>
<p style="margin: 0; margin-bottom: 10px;">
@{ var theClass = string.Concat("autocomplete", Model.Questions[i].IsYesNo ? "yesno" : Model.Questions[i].IsTime ? "time" : ""); }
@Html.TextBoxFor(model=>model.Questions[i].Answers[0].AnswerText, new {@class=theClass, question=Model.Questions[i].Id.ToString()})
@Html.ValidationMessageFor(model=>model.Questions[i].Answers[0].AnswerText)
@Html.HiddenFor(model => model.Questions[i].Id)
</p>
}
會爲每個輸入字段發送多個AJAX請求。你確定這就是你需要的嗎? – 2012-03-13 16:08:56