Microsoft.Web.Mvc Assembly 说明

本文介绍ASP.NET MVC中常用的扩展方法,包括HTML标签生成、邮件链接创建及图片显示等,帮助开发者快速掌握这些实用工具。
 

IHtmlElement

 A Html Element's Interface.
Html标签的一个接口规范。 C#:

public   interface  IHtmlElement
{
    
//  Properties
    IDictionary < string string >  Attributes {  get ; }
    
string  InnerHtml {  get set ; }
    
string  TagName {  get ; }
}

ButtonBuilder

To Builter a Button HTML tag with some attr.
用一些属性来构造Button的Html标签的构造器。
C#:
public   static   class  ButtonBuilder
{
    
//  Methods
     public   static  IHtmlElement Button( string  name,  string  buttonText,  string  onClickMethod, IDictionary < string object >  htmlAttributes);
    
public   static  IHtmlElement SubmitButton( string  name,  string  buttonText, IDictionary < string object >  htmlAttributes);
    
public   static  IHtmlElement SubmitImage( string  name,  string  sourceUrl, IDictionary < string object >  htmlAttributes);
}

 

RequireHttpMethodAttribute

Base Class:ActionFilterAttribute
可以批量设置可用的Action的列表。


[RequireHttpMethod( " index " , " about " )]
public   class  HomeController{}

则只有home/index与home/about是可以访问的。

ViewExtensions

HtmlHelperViewPage的扩展
增加了RenderAction及RenderRoute的扩展
定义
public   static   class  ViewExtensions
{
    
//  Methods
     public   static   void  RenderAction < TController > ( this  HtmlHelper helper, Expression < Action < TController >>  action)  where  TController: Controller;
    
public   static   void  RenderAction( this  HtmlHelper helper,  string  actionName);
    
public   static   void  RenderAction( this  HtmlHelper helper,  string  actionName,  string  controllerName);
    
public   static   void  RenderAction( this  HtmlHelper helper,  string  actionName,  string  controllerName,  object  values);
    
public   static   void  RenderAction( this  HtmlHelper helper,  string  actionName,  string  controllerName, RouteValueDictionary values);
    
public   static   void  RenderRoute( this  HtmlHelper helper, RouteValueDictionary values);
}




使用方法:



<%=Html.RenderUserControl("~/views/user/index-account.ascx", ViewData.Model)%>



MailToExtensions

增加了HtmlHelper的MailTo方法:



可以支持默认的转发及设置标题内容



public   static   class  MailToExtensions
{
    
//  Methods
     public   static   string  Mailto( this  HtmlHelper helper,  string  linkText,  string  emailAddress);
    
public   static   string  Mailto( this  HtmlHelper helper,  string  linkText,  string  emailAddress, IDictionary < string object >  htmlAttributes);
    
public   static   string  Mailto( this  HtmlHelper helper,  string  linkText,  string  emailAddress,  object  htmlAttributes);
    
public   static   string  Mailto( this  HtmlHelper helper,  string  linkText,  string  emailAddress,  string  subject);
    
public   static   string  Mailto( this  HtmlHelper helper,  string  linkText,  string  emailAddress,  string  subject, IDictionary < string object >  htmlAttributes);
    
public   static   string  Mailto( this  HtmlHelper helper,  string  linkText,  string  emailAddress,  string  subject,  object  htmlAttributes);
    
public   static   string  Mailto( this  HtmlHelper helper,  string  linkText,  string  emailAddress,  string  subject,  string  body,  string  cc,  string  bcc, IDictionary < string object >  htmlAttributes);
    
public   static   string  Mailto( this  HtmlHelper helper,  string  linkText,  string  emailAddress,  string  subject,  string  body,  string  cc,  string  bcc,  object  htmlAttributes);
}

ImageExtensions

HtmlHelepr的图片显示扩展:



public   static   class  ImageExtensions
{
    
//  Methods
     public   static   string  Image( this  HtmlHelper helper,  string  imageRelativeUrl);
    
public   static  IHtmlElement Image( string  imageUrl,  string  alt, IDictionary < string object >  htmlAttributes);
    
public   static   string  Image( this  HtmlHelper helper,  string  imageRelativeUrl, IDictionary < string object >  htmlAttributes);
    
public   static   string  Image( this  HtmlHelper helper,  string  imageRelativeUrl,  object  htmlAttributes);
    
public   static   string  Image( this  HtmlHelper helper,  string  imageRelativeUrl,  string  alt);
    
public   static   string  Image( this  HtmlHelper helper,  string  imageRelativeUrl,  string  alt, IDictionary < string object >  htmlAttributes);
    
public   static   string  Image( this  HtmlHelper helper,  string  imageRelativeUrl,  string  alt,  object  htmlAttributes);
}

ButtonsAndLinkExtensions

HtmlHelper的扩展



增加了Button,SubmitButton,SubmitButton的支持



public   static   class  ButtonsAndLinkExtensions
{
    
//  Methods
     public   static   string  Button( this  HtmlHelper helper,  string  name,  string  buttonText,  string  onClickMethod);
    
public   static   string  Button( this  HtmlHelper helper,  string  name,  string  buttonText,  string  onClickMethod, IDictionary < string object >  htmlAttributes);
    
public   static   string  Button( this  HtmlHelper helper,  string  name,  string  buttonText,  string  onClickMethod,  object  htmlAttributes);
    
public   static   string  SubmitButton( this  HtmlHelper helper);
    
public   static   string  SubmitButton( this  HtmlHelper helper,  string  name);
    
public   static   string  SubmitButton( this  HtmlHelper helper,  string  name,  string  buttonText);
    
public   static   string  SubmitButton( this  HtmlHelper helper,  string  name,  string  buttonText, IDictionary < string object >  htmlAttributes);
    
public   static   string  SubmitButton( this  HtmlHelper helper,  string  name,  string  buttonText,  object  htmlAttributes);
    
public   static   string  SubmitImage( this  HtmlHelper helper,  string  name,  string  imageSrc);
    
public   static   string  SubmitImage( this  HtmlHelper helper,  string  name,  string  imageSrc, IDictionary < string object >  htmlAttributes);
    
public   static   string  SubmitImage( this  HtmlHelper helper,  string  name,  string  imageSrc,  object  htmlAttributes);
}

 

Wiki:http://www.eice.com.cn/Microsoft_Web_Mvc.ashx

An unhandled exception occurred while processing the request. InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'TeamListViewModel', but this ViewDataDictionary instance requires a model item of type 'UserManagementSystem.Web.Models.ViewModels.TeamListViewModel'. Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary..ctor(ViewDataDictionary source, object model, Type declaredModelType) Stack Query Cookies Headers Routing InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'TeamListViewModel', but this ViewDataDictionary instance requires a model item of type 'UserManagementSystem.Web.Models.ViewModels.TeamListViewModel'. Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary..ctor(ViewDataDictionary source, object model, Type declaredModelType) lambda_method443(Closure , ViewDataDictionary ) Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context) Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, bool invokeViewStarts) Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context) Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable<int> statusCode) Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable<int> statusCode) Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, string contentType, Nullable<int> statusCode) Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result) Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|30_0<TFilter, TFilterAsync>(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext<TFilter, TFilterAsync>(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters() Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) Program+<>c+<<<Main>$>b__0_3>d.MoveNext() in Program.cs + await next(); Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context) Show raw exception details
10-07
An unhandled exception occurred while processing the request. InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'TeamListViewModel', but this ViewDataDictionary instance requires a model item of type 'UserManagementSystem.Web.Models.ViewModels.TeamListViewModel'. Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.EnsureCompatible(object value) Stack Query Cookies Headers Routing InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'TeamListViewModel', but this ViewDataDictionary instance requires a model item of type 'UserManagementSystem.Web.Models.ViewModels.TeamListViewModel'. Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.EnsureCompatible(object value) lambda_method399(Closure , ViewDataDictionary ) Microsoft.AspNetCore.Mvc.Razor.RazorPagePropertyActivator.Activate(object page, ViewContext context) Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context) Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, bool invokeViewStarts) Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context) Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable<int> statusCode) Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable<int> statusCode) Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, string contentType, Nullable<int> statusCode) Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result) Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|30_0<TFilter, TFilterAsync>(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext<TFilter, TFilterAsync>(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters() Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) Program+<>c+<<<Main>$>b__0_3>d.MoveNext() in Program.cs + await next(); Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context) Show raw exception details
10-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值