MVC Note

Deploy

Problem:required providerName attribute

Description

There is an error when I change the database fromLocalDB to SQL Server, The connection string ‘EFDbContext’ in the application’s configuration file does not contain the required providerName attribute
The main problem is configuration of Web.config at the root,The value of the attribute was put at connectionString.

Previous configuration :

<add name=”EFDbContext” connectionString=”Data Source=CN-LIA-NB1\SQLEXPRESS;Initial Catalog=SportsStore;User ID=sa; Password=Roding;providerName=System.Data.SqlClient;MultipleActiveResultSets=true” />

Correct configuration:

<add name=”EFDbContext” providerName=”System.Data.SqlClient” connectionString=”Data Source=CN-LIA-NB1\SQLEXPRESS;Initial Catalog=SportsStore;User ID=sa; Password=Roding;MultipleActiveResultSets=true”/>

Reference:

http://forums.asp.net/t/1858681.aspx?The+connection+string+EFDbContext+in+the+application+s+configuration+file+does+not+contain+the+required+providerName+attribute+

ActionResult does not contain ViewData

Description

在unit test的测试方法中,index()返回值无法引用属性ViewData

CartIndexViewModel result = (CartIndexViewModel)target.Index(cart, “myUrl”).ViewData.Model;

原因是由于Index()返回值的类型是ActionResult,而ActionResult是抽象类,没有该属性,该属性是由ViewResultBase所有。
ViewResult继承ViewResultBase,而ViewResultBase继承于ActionResult

Solution

Force cast to ViewResult:

Product[] result = ((IEnumerable)((ViewResult)target.Index()).ViewData.Model).ToArray();

在cshtml页面中使用拓展方法会报不支持动态转换

It need explicitly cast
@Html.PageLinks(Model.PagingInfo, x=>Url.Action(“List”,new { page =x, category = Model.CurrentCategory }))

Free IIS server

国内很难找,都是以各种各样的理由收费。
尤其是阿里云,以前还有免费的,现在好,捆绑销售CDN,一年30块。
然后还要备案,在阿里云备案需要买阿里云专用背景布,真真笑死人。
最后还要买域名,我快晕死了,到现在网站还没搭好,钱花了好几笔了,如果你是学习的,请远离阿里云。

所以只能把目光投到国外了,外国人做事比较靠谱,下面这个可以用:
https://somee.com
注册完网站就可以用了,是支持IIS的。
这是我根据书上做的运动购物网站,欢迎来访:
SportsStore
这个网站的缺点是网速慢,如果是VPN会好一点

传说中的阿里云幕布终于到了,从上海到无锡,两天的时间,速度马马虎虎。不过打开我笑哭了,这是布啊
这就是纸嘛,终于明白淘宝天猫到处是假货了,原来是上梁不正。 本来还想拍完照,拿回去当抹布呢,这下好。 等我把文件上传上去之后,发现网站打不开,一问之下,不支持MVC5. 之前做的工作白费。
alibackgroud


Allen Li

Allen Li

Just another boring, tattooed, time traveling designer.


Updated