顯示具有 ASP.NET MVC 標籤的文章。 顯示所有文章
顯示具有 ASP.NET MVC 標籤的文章。 顯示所有文章

2017年6月19日 星期一

【AutoMapper】None static centralized configuration

想把 AutoMapper 的設定作個集中,但找到的教學都是用 Initialize 做靜態的,而沒有新版建議的 IMapper 實體導向的作法,參考了 SO 得其中一篇作了簡單的設置,算不上 best practice 但有興趣的人還是可以參考下。

2017年5月30日 星期二

2017年5月28日 星期日

【ASP.NET MVC】Encountered an unexpected error when attempting to resolve tag helper directive '@addTagHelper' ...

在 MVC Controllers 加入 具有檢視、使用 Entity Framework 的 MVC 5 控制器,View 端噴錯噴得亂七八糟的,但要是按執行還是很神奇的可以跑起來。

Encountered an unexpected error when attempting to resolve tag helper directive '@addTagHelper' with value 'Microsoft.AspNet.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNet.Mvc.Razor'. Error: Object reference not set to an instance of an object

The type or namespace name 'AspNet' does not exist in the namespace 'Microsoft' after add controller with view

The type or namespace name 'Mvc' does not exist in the namespace 'Microsoft.AspNet' (are you missing an assembly reference?)

還有
'_Page_views_home_index_cshtml.ExecuteAsync()': no suitable method found to override

2017年1月10日 星期二

【ASP.NET MVC】The resource cannot be found.

找不到資源。

The resource cannot be found. Description: HTTP 404. The resource you are looking for (... 之類的

2017年1月5日 星期四

【ASP.NET MVC】The model item passed into the dictionary is of type 'TypeA' but this dictionary requires a model item of type 'TypeB'

The model item passed into the dictionary is of type 'TypeA' but this dictionary requires a model item of type 'TypeB'

在 Html.RenderPartial(..., TypeB) 時發生
傳入此字典的模型項目為型別 'TypeA',但是此字典需要型別 'TypeB' 的模型項目。
的錯誤。

2016年1月7日 星期四

【ASP.NET MVC】Internal Server Error when JQuery Ajax post

用 JQuery Ajax post 時候發現沒 cue 到後端,Console 出
POST http://localhost:XXXX/Controller/Action 500 (Internal Server Error)

2015年12月28日 星期一

【ASP.NET MVC】The parameters dictionary contains a null entry for parameter 'XXX' of non-nullable type 'System.Type' for method 'System.Web.Mvc.ActionResult GetYYY(System.Type)' in 'Namespace.XXXController'.

對 'Namespace.XXXController' 的方法 'System.Web.Mvc.ActionResult GetXXX(System.Type)' 中不可為 null 型別 'System.Type' 的參數 'YYY' 而言,參數字典含有 null 項目。選擇性參數必須是參考型別、可為 null 的型別,或必須宣告為選擇性參數。

2015年11月3日 星期二

【ASP.NET MVC】JQuery validate parameters rule and customer message not working

// 錯誤示範
$("#form1").validate({
    rules: {
        txtName: "required",
        txtAge: {
            required: true,
            min: 18
        }
    },
    messages: {
        required: "*必填欄位",
        min: jQuery.validator.format("*年齡須大於{0}")
    }
});
在試客戶端驗證時碰到的問題

2015年10月27日 星期二

【ASP.NET MVC】JSON from client to server



範例會在 Client 端動態產生 table row 暫存資料,並在 submit 前將表格資料轉為 JSON 格式字串寫入 hiddenfield 以轉給後端,後端會將讀入的 JSON 字串反序列化為 List 後進行簡單的過濾,並再次回給前端。

2015年10月22日 星期四

【Entity Framework】Anonymous type query

Using stored procedure to select an anonymous type result set
在使用 EF 的 ASP.NET MVC 專案中需要跑一段預存程序然後回傳一組不具名型別的資料,
類似

SELECT Student.Name, Class.Name FROM Student INNER JOIN Class ON Student.ClassId = Class.Id

這個 Query 出來的結果就是一個新的型別(既不屬於 Student 也不是 Class),偏偏 EF 的設計就是希望你弄出來的東西是強型別的,而不是像 DataTable 這類的東西(我本來一直天真的以為一定會有可以 Query Result 是 DataSet 或 DataTable)。

2015年10月6日 星期二

【ASP.NET MVC】Ambiguous action

對控制器類型 'BBBController' 上動作 'Action' 的目前要求,在下列動作方法之間模稜兩可: 
型別 a.b.c.BBBController 上的 System.Web.Mvc.ActionResult Action(a.b.c.BBBViewModel)
型別 a.b.c.AAAController 上的 System.Web.Mvc.ActionResult Action(a.b.c.AAAViewModel)

這個錯誤讓我還蠻意外的

2015年8月12日 星期三

2015年7月31日 星期五

ASP.NET MVC5 實戰訓練營週末班


我本身是寫 Web Form 出身的( 學校4年左右 + 工作 1年多 ),最近重找工作發現 MVC 需求熱絡化因而覺得自己需要轉型所以加入課程。