标签: htmlextensions

MVC 3 htmlhelper扩展方法来包装内容

我搜索但找不到MVC 3 htmlhelper的任何快速解决方案来创建包装器方法.我正在寻找的是:

@html.createLink("caption", "url")
{
    <html> content in tags </html>
}
Run Code Online (Sandbox Code Playgroud)

结果应该有

<a href="url" title="Caption">
  <html> content in tags </html>
</a>
Run Code Online (Sandbox Code Playgroud)

对此有任何帮助.

asp.net htmlextensions razor asp.net-mvc-3

18
推荐指数
2
解决办法
1万
查看次数

使用HTML扩展的值与两个模型具有相同名称的属性时的值不同

这是我的情景.

  1. 创建了两个具有公共属性名称的模型

    public class SimpleModel1
    {
    // Some Properties
    
    public string Property1 { get; set; }
    
    }
    
    public class SimpleModel2
    {
    // Some Properties
    
    public string Property1 { get; set; } // Same name as Property1 in SimpleModel1
    
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. 在Action(例如Index)中使用SimpleModel1,返回看起来像这样的视图

    @model MvcApplication2.Models.SimpleModel1
    
    @{
    ViewBag.Title = "Home Page";
    }
    
    @using (Html.BeginForm("Test", "Home", FormMethod.Post))
    {
      <label>Enter something here</label>
       @Html.TextBoxFor(m => m.Property1)
       <button type="submit">Submit</button>
    }
    
    Run Code Online (Sandbox Code Playgroud)
  3. 将值提交给将SimpleModel1作为参数的Test操作,做一些工作,并返回一个接受SimpleModel2的视图

    public ActionResult Test(SimpleModel1 model)
    {
        SimpleModel2 newModel = new SimpleModel2();
    
        // Do Something
    
        newModel.Property1 = "Something different …
    Run Code Online (Sandbox Code Playgroud)

properties htmlextensions razor asp.net-mvc-4

6
推荐指数
1
解决办法
1572
查看次数

在ASP.NET Repeater Control中将Container.Eval传递给(Html.ReaderPartial)

我试图将Eval传递给ASP.NET Repeater中的Html.RenderPartial,但它无法正常工作吗?

<asp:Repeater runat="server">
            <ItemTemplate>
                <% Html.RenderPartial("UserControl1",Eval("Title")); %>
            </ItemTemplate>
</asp:Repeater>
Run Code Online (Sandbox Code Playgroud)

顺便说一句,我知道我可以通过其他方式做到这一点,但我想知道它是否可行.

asp.net asp.net-mvc repeater htmlextensions

2
推荐指数
1
解决办法
1577
查看次数

ASP.Net MVC 3 - Html扩展

我正在玩Razor + MVC 3并且有一个非常简单的场景......基本上我正在尝试创建一个非常基本的HTML帮助器但是我得到以下异常:

'System.Web.Mvc.HtmlHelper'不包含'ScriptCss'的定义,并且没有扩展方法'ScriptCss'接受类型为'System.Web.Mvc.HtmlHelper'的第一个参数'(你是否缺少using指令)或汇编参考?)

扩展的代码如下所示:

    public static MvcHtmlString ScriptCss(this HtmlHelper htmlHelper, string path)
    {
        return MvcHtmlString.Create(String.Format("<link rel=\"stylesheet\" type=\"text/css\" href=\"{0}\" />", path));
    }
Run Code Online (Sandbox Code Playgroud)

我想去的任何想法?

干杯安东尼

.net htmlextensions razor asp.net-mvc-3

2
推荐指数
1
解决办法
4666
查看次数