自分で作ったり提供したりするものは、まず自分自身で使ってみろろということです。自分じゃ使わないものなら人はいくらでも無責任にも無思考にもなれる。そういう投げやりな「サービス」やら「プロダクツ」なんて、だれだってイヤだ。自分が作り手と同時に利用者の立場になれば、ちゃんと使えるレベルのものを提供しようとします。

ラベル Asp.Net MVC2 の投稿を表示しています。 すべての投稿を表示
ラベル Asp.Net MVC2 の投稿を表示しています。 すべての投稿を表示

2010年11月10日水曜日

asp.net mvc2 controller attributeサンプル

asp.net mvc2フレームワークのコントローラー属性を定義するサンプルです。

ShowMessageAttribute.cs
namespace MvcApplicationEmpty.Attributes
{
    public class ShowMessageAttribute : ActionFilterAttribute
    {
        public string Message { get; set; }

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //base.OnActionExecuting(filterContext);
            filterContext.HttpContext.Response.Write("[OnActionExecuting " + Message + "]");
        }
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            //base.OnActionExecuted(filterContext);
            filterContext.HttpContext.Response.Write("[OnActionExecuted " + Message + "]");
        }
        public override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            //base.OnResultExecuting(filterContext);
            filterContext.HttpContext.Response.Write("[OnResultExecuting " + Message + "]");
        }
        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            //base.OnResultExecuted(filterContext);
            filterContext.HttpContext.Response.Write("[OnResultExecuted " + Message + "]");
        }
    }
}

asp.net mvc複数ボタンの処理

asp.net mvcフレームワークのformに複数のSubmitボタンを配置して、押したボタン情報のみサーバーに送信する処理を説明します。

①まずViewModelにCmdプロパティを定義する。
public string Cmd { get; set; }

②画面にSubmitボタンを配置する。
<button name="Cmd" value="btn1">確定1</button>
<button name="Cmd" value="btn2">確定2</button>

③コントローラーにCmd引数を判定して、ボタン処理を振り分ける。
[HttpPost]
public ViewResult DoLink2(GuestResponse pobjGuestResponse)
{
    switch (pobjGuestResponse.Cmd)
    {
        case "btn1":
            break;
        case "btn2":
            break;
    }
...
}

asp.net mvc2メモ

参照用ソースのメモです。
1、Controllersフォルダにコントローラーを作る
2、Viewsフォルダにコントローラーごとにフォルダを作って、下にコントローラーメッソド(Action)ごとにビューページを作る
3、Global.asax.csにデフォールトページ或はコントローラーを指定する

2010年8月20日金曜日

URLルート知識

URLルート追加:
routes.MapRoute(
    "Default",                                      // Route name
    "{controller}/{action}/{id}",                   // URL with parameters
    new { controller = "Home", action = "Index",    // Parameter defaults
          id = UrlParameter.Optional }
);

本来の書き方:
Route myRoute = new Route("{controller}/{action}/{id}", new MvcRouteHandler())
{
    Defaults = new RouteValueDictionary( new {
        controller = "Home", action = "Index", id = UrlParameter.Optional
    })
};
routes.Add("Default", myRoute);

2010年8月17日火曜日

Asp.Net MVC2必須技術のまとめ

Ninject
http://ninject.org/

WatiN
http://watin.sourceforge.net/

moq
http://code.google.com/p/moq/

オプション:(勉強したほうがいい)
SpecFlow
http://specflow.org/

ホームページ