我想發回一個categoryId並用新的強類型對象更新頁面。出於某種原因,cateogryId在爲空來了...asp.net MVC空字符串參數
$(function() {
$('#hhh').change(function() {
var url = $(this).data('url');
var categoryId = $(this).val();
$.ajax({
url: url,
type: 'GET',
cache: false,
data: { categoryId: categoryId },
success: function (result) {
// TODO: manipulate the result returned from the controller action
}
});
});
});
<h2>Index</h2>
@Html.ActionLink("Create New Listing", "Create")
<br/>
<strong>Filter Listings</strong>
@Html.DropDownListFor(
m => m.SelectedCategoryGuid,
Model.Categories,
"Select a Category",
new {
id = "hhh",
data_url = Url.Action("SortListing", "Listing")
}
)
控制器代碼:
public ActionResult SortListing(string categoryGuid)
{
var listingCategory = new ListingCategory();
listingCategory.Id = _tourismAdminService.GetByGuid<ListingCategory>(Guid.Parse(categoryGuid)).Id;
var listings = new List<Listing>();
foreach (var listing in _tourismAdminService.ListAllEntities<Listing>())
{
if (listing.CategoryId == listingCategory.Id)
{
listings.Add(listing);
}
}
return RedirectToAction("Index", "Listing", listings);
}
請發表您的'Controller'的操作方法。 – Gromer
嗨。我添加了控制器代碼 – Subby