可有人能幫助我找到:模式不具約束力的行動
型號:
public class CreateAdCategoryViewModel
{
[Display(ResourceType = typeof(HeelpResources), Name = "AdViewModel_Category_Label")]
[Required(ErrorMessageResourceName = "AdViewModel_Required_ErrorMsg", ErrorMessageResourceType = typeof(HeelpResources))]
public int Category_Id { get; set; }
public IEnumerable<SelectListItem> CategoryList { get; set; }
public CreateAdCategoryViewModel(IEnumerable<SelectListItem> categoryList)
{
CategoryList = categoryList;
}
}
控制器:
[Authorize]
[HttpPost]
public virtual PartialViewResult CreateAdCategoryType(CreateAdCategoryViewModel model)
{
// Build the ViewModel to return to the View with the Category Drop List
return PartialView(new CreateAdCategoryTypeViewModel(CategoryDropDownList()));
}
查看:
@model Heelp.ViewModels.CreateAdCategoryViewModel
@using (Ajax.BeginForm(MVC.Ad.CreateAdCategoryType(), new AjaxOptions { UpdateTargetId = "category_type", InsertionMode = InsertionMode.Replace }, new { @id = "categoryForm" }))
{
@Html.DisplayNameFor(m => m.Category_Id)
@Html.DropDownListFor(m => m.Category_Id, Model.CategoryList, HeelpResources.DropdownlistCategoryFirstRecord)
@Html.ValidationMessageFor(m => m.Category_Id)
}
使用Javascript進行提交:
$(document).ready(function()
{
$("#Category_Id").change(function()
{
$("#categoryForm").submit();
});
});
的這裏的問題是,提交從未發現的動作CreateAdCategoryType
與模式參數,爲什麼呢?
可能是因爲你的模型有參數化構造函數,MVC不知道如何調用它? –
是的你是正確的,我脫下構造函數,一切正常,所以我怎麼能有一個構造函數來簡化模型返回到視圖使用不同的方法? – Patrick