C# 复选框作为ASP.net MVC 4或5中的链接

C# 复选框作为ASP.net MVC 4或5中的链接,c#,asp.net-mvc-4,checkbox,asp.net-mvc-5,C#,Asp.net Mvc 4,Checkbox,Asp.net Mvc 5,是否可以在ASP.net MVC 4或5中创建一个复选框作为参数链接,该参数引用控制器的AcionResult?是,您可以通过创建自定义html帮助程序来实现这一点。 在custom helper中,您可以制作任何想要的东西 例如: public static MvcHtmlString CheckBoxLabelFor<TModel>(this HtmlHelper<TModel> pHtml, Expression<Func<TModel,

是否可以在ASP.net MVC 4或5中创建一个复选框作为参数链接,该参数引用控制器的AcionResult?

是,您可以通过创建自定义html帮助程序来实现这一点。 在custom helper中,您可以制作任何想要的东西

例如:

       public static MvcHtmlString CheckBoxLabelFor<TModel>(this HtmlHelper<TModel> pHtml, Expression<Func<TModel, bool>> pExpression, IDictionary<string, Object> pLabelHtmlAttributes, string pCaption)
    {
        try
        {
            MvcHtmlString tCheckBox;
            string tCheckBoxWithLabel;
            TagBuilder tBuilder;

            tCheckBox = InputExtensions.CheckBoxFor(pHtml, pExpression);
            tBuilder = new TagBuilder("label");
            tBuilder.MergeAttributes(new RouteValueDictionary(pLabelHtmlAttributes));

            tCheckBoxWithLabel ="<a>" + tBuilder.ToString(TagRenderMode.StartTag) + tCheckBox.ToString() + pCaption + "</label></a>";

            return MvcHtmlString.Create(tCheckBoxWithLabel);
        }
        catch (Exception ex)
        {
            clsINFEventLogger.LogEvent(mdlEnumerations.INFEventTypes.Error, ex.Message, ex.StackTrace);
            return null;
        }

    }
public static MvcHtmlString CheckBoxLabelFor(此HtmlHelper pHtml、表达式pExpression、IDictionary plabelHtmlatAttribute、字符串pCaption)
{
尝试
{
MVCHTML字符串检查框;
字符串tCheckBoxWithLabel;
TagBuilder-tBuilder;
checkbox=InputExtensions.CheckBoxFor(pHtml,pExpression);
tBuilder=新标记生成器(“标签”);
合并属性(新的RouteValueDictionary(PlabelHtmlatAttributes));
tCheckBoxWithLabel=”

您可以根据需要编辑自定义帮助程序:)

可能您可以使用JavaScript进行编辑,但请提供更多信息说明您正在尝试执行的操作,并共享一些代码。
 @Html.CheckBoxLabelFor(model => model.Test,new Dictionary<string, object> {  { "onclick", "location.href= '" + @Url.Action(YourController, YourAction, Model) + "'" } }, "Test Caption")
<a><label onclick="location.href= '/Namespace/YourController/YourAction'"><input id="Test" name="Test" type="checkbox" value="true">Test</label></a>