AJAX 呼び出しで、文字列値を呼び出し元のページに返したいと考えています。
文字列を使用するActionResultか、単に返す必要がありますか?
AJAX 呼び出しで、文字列値を呼び出し元のページに返したいと考えています。
文字列を使用するActionResultか、単に返す必要がありますか?
ContentResultを使用して、プレーンな文字列を返すことができます。
public ActionResult Temp() {
return Content("Hi there!");
}
ContentResultデフォルトでは、contentTypetext/plainとしてaを返します。これはオーバーロード可能であるため、次のこともできます。
return Content("<xml>This is poorly formatted xml.</xml>", "text/xml");
メソッドが返すのはそれだけであることがわかっている場合は、文字列を返すこともできます。例えば:
public string MyActionName() {
return "Hi there!";
}
public ActionResult GetAjaxValue()
{
return Content("string value");
}