私はこれと同様の問題を抱えていましたが、その解決策はここでは適用されないようです。私はビューのドロップダウンで選択された選択肢の選択に従ってビューデータをソートするために、オーバーロードされたリポジトリ機能を呼び出そうとしています。asp.net mvcのリポジトリで関数を実行するにはどうすればよいですか?
"onchange"イベントを使用してjavascriptを実行しましたが、オーバーロードが一致せず、正しくバインドする方法がわからないため、リポジトリ機能を実行しようとしました。提供されたすべてのヘルプは非常に高く評価されます。
マイHtmlのビュー
<select id="sortSelect" onchange="CallChangeFunction()">
<option value="default">Default</option>
<option value="make">Make</option>
<option value="model">Model</option>
<option value="year">Year</option>
</select>
<script>
function CallChangeFunction(val) {
alert("Do something here to make it sort!");
}
</script>
マイリストリポジトリ
IEnumerable<ListingStat> GetListingStats(int inCompanyID, int inMonth, int inYear);
public IEnumerable<ListingStat> GetListingStats(int inCompanyID, int inMonth, int inYear)
{
//var x = document.getElementById("sortSelect").value;
// there's probably a way to make ef do this query in an efficient manner.. but, there aren't nice keys between listingstats and makemodel stats, and I'm not going to create them for the sake of ef
var theSQL = "select d.DatePK, ls.*, " +
"mm.Make as MM_Make, mm.Model as MM_Model, mm.ListingsThatWereActive as MM_ListingCount, mm.MedianPriceExcludeZero as MM_MedianPrice, mm.PopularityRank as MM_PopularityRank, " +
"mm.PopularityMaxRank as MM_PopularityMaxRank, mm.AverageFavorites as MM_Favorites, mm.AverageSearchImpressions as MM_SearchImpressions, mm.AverageBuyerInquiries as MM_BuyerInquiries, mm.AveragePhoneInquiries as MM_PhoneInquiries, mm.AverageListingViews as MM_ListingViews, " +
"ymm.SupplyDemandIntegerPercentile as YMM_SupplyDemandPercentile, ymm.TotalListingViews as YMM_TotalListingViews " +
"from " +
"PerformanceDataMart.Dates d " +
"left outer join PerformanceDataMart.ListingStats ls on ls.DateFK = d.DatePK and ls.CompanyId = :CompanyID " +
"left outer join PerformanceDataMart.MakeModelStats mm on mm.DateFK = d.DatePK and mm.Make = ls.Make and mm.Model = ls.Model and mm.Year is null " +
"left outer join PerformanceDataMart.MakeModelStats ymm on ymm.DateFK = d.DatePK and ymm.Make = ls.Make and ymm.Model = ls.Model and ymm.Year = ls.Year " +
"where d.Month = :Month and d.Year = :Year";
var theDB = new CCDB();
List<ListingStat> theList = new List<ListingStat>();
using (IDataReader aDR = theDB.OpenDataReader(theSQL, inCompanyID, inMonth, inYear))
{
while(aDR.Read())
{
ListingStat theListingStat = new ListingStat();
theList.Add(theListingStat);
theListingStat.ListingId = As.Integer(aDR["ListingId"]);
theListingStat.Year = As.Integer(aDR["Year"]);
theListingStat.Make = As.String(aDR["MM_Make"]);
if (theListingStat.Make == "") // shouldn't happen, but just in case
theListingStat.Make = As.String(aDR["Make"]);
theListingStat.Model = As.String(aDR["MM_Model"]);
if (theListingStat.Model == "") // shouldn't happen, but just in case
theListingStat.Model = As.String(aDR["Model"]);
}
}
return theList;
}
:
あなたの機能は次のようになります。あなたができないことを具体的に言いなさい。希望のアクションメソッドをjavascriptから呼び出すことができませんか?コントローラから目的のリポジトリメソッドに... –
私はhtmlビューのjavascriptからアクションメソッドを呼び出そうとしています。オーバーロードされたメソッドをどのように処理するのか分かりません。 – csharpMind