1.从Html代码抽取MVC HtmlHelper
<td class = "noborder nopaddingv"> <div class = "aligncenter"> <a href="/Home/Index"> <img src="../../Resouces/Images/Agile/Menu/Campass48.png" alt = "站点地图" title = "站点地图" class = "imagelink"/></a><br /> 站点地图 </div> </td> <td class = "noborder nopaddingv"> <div class = "aligncenter"> <a href="/Home/Index" target = "_blank"> <img src="../../Resouces/Images/Agile/Help/Help48.png" alt = "帮助" title = " 帮助" class = "imagelink"/></a><br /> 帮助 </div> </td>改后:
@Html.MenuImageButtonV("站点地图", false, "/Home/Index",
"../../Resouces/Images/Agile/Menu/Campass48.png") @Html.MenuImageButtonV("帮助", true, "/Home/Index", "../../Resouces/Images/Agile/Help/Help48.png")这种技法:当两段代码相同时,可以变成一个函数和两次调用,相同的部分就是函 数,不同的部分就是调用参数。 2.函数接口的简洁性:不是编写了函数就万事大吉了,不好的函数接口依然不简洁。下面是一个刚改好的
例子:@Html.ImageLink("燃烧图", true,
"../../Resouces/Images/Agile/CurrentSprint/BurndownData16.png", "icons", false, "/Agile/CurrentSprint/BurndownData", null, null)@Html.ImageLink("迭代计划", true,
"../../Resouces/Images/Agile/Sprints/Index16.png", "icons", false, "/Agile/Sprints/Index", null, null)...
修改后的结果(另外一段代码):@Html.ImageLink("迭代计划", "/Agile/Sprints/Index", true) //这个true有些
地方不太一样所以留下了。@Html.ImageLink("迭代故事", "/Agile/Sprints/SprintStories", true)这种技法:如果函数在重复调用时有些参数变化,有些参数基本不变("icons", true, false, null....),后者应该变成一些可选参数并设置缺省值。