0
我的視圖是腳手架生成的列表。對於列表中的模式是:模型綁定對於MVC中的Ajax.BeginForm失敗5
public class LogsViewModel
{
public string Category { get; set; }
public string ClientIP { get; set; }
public string StartDate { get; set; }
public string EndDate { get; set; }
public string Message { get; set; }
}
要過濾整個列表,我提供了一種具有多個輸入元件,例如自舉模態形式:類別,clientip,日期和消息。這種模式的形式使用Ajax.BeginForm以下方式:在控制器
@using (Ajax.BeginForm(
new AjaxOptions
{
HttpMethod = "get",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "results"
}))
{
<fieldset>
<div class="form-group">
<label for="recipient-name" class="control-label">Category:</label>
<select class="form-control" id="Category">
<option>Information</option>
<option>General Error</option>
</select>
@*<input type="text" class="form-control" id="category">*@
</div>
<div class="form-group">
<label for="recipient-name" class="control-label">IP:</label>
<input type="text" class="form-control" id="ClientIP">
</div>
<div class="form-group" id="startDTPicker" style="position:relative">
<label for="recipient-name" class="control-label" id="startDate">Start Date:</label>
<input type="text" class="form-control" id="StartDate">
</div>
<div class="form-group" id="endDTPicker" style="position:relative">
<label for="recipient-name" class="control-label" id="endDate">End Date:</label>
<input type="text" class="form-control" id="EndDate">
</div>
<div class="form-group" id="startDTPicker">
<label for="recipient-name" class="control-label">Message:</label>
<input type="text" class="form-control" id="Message">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<input type="submit" class="btn btn-primary" value="Show Results" />
</div>
</fieldset>
}
於是,我試圖讓這些參數(類別= ...)。我已經宣佈ActionMethod爲:
public ActionResult Index(LogsViewModel viewModel)
{
//all the properties are null when the Ajax request invokes this method
}
什麼是導致問題,什麼是最好的處理方式?
使用HTML輔助或補充name屬性 – Umer