1

私はASP.NETMVCWebサイトに取り組んでいますが、これは初めてです。アクションの少ないコントローラーがあります。これらのアクションを自分のWebサイト全体で使用したいと思います。例えば

[HttpPost]
public ActionResult MyAction(ViewModel model)
{

    if (ModelState.IsValid)
    {
        //code is here
    }
  return RedirectToAction(); // redirect to same view

}

リクエストが生成された場所から同じビューにリダイレクトしたい。これが可能かどうかわかりませんか?

4

1 に答える 1

0

あなたのコメントに基づいて、次のようなコントローラーを作成します。

public MyController : Controller
{
  private ActionResult SharedMethod(SomeModel model)
  {
    if (ModelState.IsValid)
    {
      //code is here
    }

    // viewname is required, otherwise the view name used will be
    // the original calling method (ie public1.cshtml, public2.cshtml)
    return this.View("SharedViewName");
  }

  public ActionResult Public1(SomeModel model)
  {
    return this.SharedMethod(model);
  }

  public ActionResult Public1(SomeModel model)
  {
    return this.SharedMethod(model);
  }
}
于 2012-12-31T18:02:48.610 に答える