オブジェクトを作成しますパラメータは自動的に私のカスタムオブジェクトに解析されますか?ASP.NET MVCコントローラのパラメータが自動的に
私にとってはうまくいかない - これはできますか?
編集:
これは私の全体のコントローラクラスである:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Tradeshow.Models;
namespace Tradeshow.Controllers
{
[Authorize]
public class DashboardController : Controller
{
public ActionResult GetResponseStats(StatisticsRequest statsRequest)// string profileid, string analysis, string question, string answer, string omitheaders)
{
Tradeshow.Models.Mongo mongo = new Models.Mongo();
// For top-level requests that don't specify the analysis, use the previously requested top-level analysis
if (statsRequest.IsTopLevelRequest)
{
if (statsRequest.Analysis == null || statsRequest.Analysis.Length == 0)
{
statsRequest.Analysis = (String)Session["statsanalysistype"];
}
else
{
Session["statsanalysistype"] = statsRequest.Analysis;
}
}
string clientdatabasename = (String)Session["clientdatabasename"];
Dashboard dashboard = mongo.BuildResponseDashboard(clientdatabasename,statsRequest);
return PartialView("ProfileDashboard",dashboard);
}
}
}
これは私の全体StatisticsRequestオブジェクトです:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Tradeshow.Models
{
/// <summary>
/// Encapsulates the properties that make up a statistics request for generating one or more graphs and charts
/// </summary>
public class StatisticsRequest
{
public string Level { get; set; }
public string Analysis { get; set; }
public string ProfileId { get; set; }
public string Question { get; set; }
public string Answer { get; set; }
public string TimespanFormat { get; set; }
public string TimespanValue { get; set; }
public bool OmitHeaders
{
get
{
bool rc = false;
if (String.Compare(Level, "profile", true) == 0) rc = true;
return rc;
}
}
public bool IsTopLevelRequest
{
get
{
bool rc = false;
if (String.Compare(Level, "profile", true) == 0) rc = true;
return rc;
}
}
}
}
と(失敗した)最も簡単なテストクエリ文字列ルックスこのように:
/Dashboard/GetResponseStats?profileid=123&unique=775765
多くの場合、パラメータの1つまたは2つだけがクエリ文字列に渡されます。
EDIT2
もう一つのポイント - StatisticsRequestオブジェクトだけで任意のオブジェクトで、ビューモデルとは何の関係もありません。フォームベースのビューなどをサポートしないように、リクエストをカプセル化するためにStatisticsRequestオブジェクトを作成しました。
「その他のプロパティ」とは何ですか? – NerdFury
はい、これは動作します。何がうまくいかないかを理解するのに役立つアクション、モデル、クエリ文字列パラメータに関する詳細情報が必要です。 – nikmd23
@ nikmd23とNerdFury - 私は詳細を表示するために投稿を編集しました。ご協力いただきありがとうございます。 – Journeyman