GVKun编程网logo

html开发日记-form button(html form 教程菜鸟教程)

4

对于想了解html开发日记-formbutton的读者,本文将是一篇不可错过的文章,我们将详细介绍htmlform教程菜鸟教程,并且为您提供关于asp.net-mvc–Html.BeginForm()

对于想了解html开发日记-form button的读者,本文将是一篇不可错过的文章,我们将详细介绍html form 教程菜鸟教程,并且为您提供关于asp.net-mvc – Html.BeginForm()工作正常,Html.BeginForm(“action”,“controller”)忽略[AllowHtmlAttribute]、asp.net-mvc – 将@ Html.RadioButtonFor设置为默认选中、asp.net-mvc-3 – 使用Html.RadioButtonFor和Html.LabelFor为相同的模型,但不同的值、Button UI Kit CSS3漂亮Button按钮_html/css_WEB-ITnose的有价值信息。

本文目录一览:

html开发日记-form button(html form 教程菜鸟教程)

html开发日记-form button(html form 教程菜鸟教程)

                    <form action="#" id="loginForm">
                        <div>
                            <labelfor="username">用户名</label>
                            <input type="text" placeholder="example@gmail.com" title="Please enter you username" required="" value="" name="username" id="username">
                            <span>请输入您的用户名</span>
                        </div>
                        <div>
                            <labelfor="password">密码</label>
                            <input type="password" title="Please enter your password" placeholder="******" required="" value="" name="password" id="password">
                            <span>请输入您的密码</span>
                        </div>
                        <div>
                            <input type="checkbox"checked>
                                  记住登录
                            <p>(注意密码安全)</p>
                        </div>
                        <buttonLogin="Login">登录</button>
                        <ahref="#">注册</a>

                    </form>

<script>

$(function(){

    $("Login^=Login").on(''click'',function(){

        location.href="other.html";

}):

});

</script>

居然不跳转。。。神奇问题,后面发现button放在form中不管用,修改为a或者input type=“button”就好了

asp.net-mvc – Html.BeginForm()工作正常,Html.BeginForm(“action”,“controller”)忽略[AllowHtmlAttribute]

asp.net-mvc – Html.BeginForm()工作正常,Html.BeginForm(“action”,“controller”)忽略[AllowHtmlAttribute]

我在我的网站的管理面板上使用 TinyMCE editor,所以我用[AllowHtml]装饰模型属性(tinymce的目标),并在视图中使用Html.BeginForm().当我提交带有HTML字段的表单时,一切正常.

但是我有一个问题,如果我以相同的方式使用重载Html.BeginForm(“action”,“controller”),它会跳过[AllowHtml]并抛出众所周知的Request.form异常.
我被迫在Action-Method上使用[ValidateInput(false)]来使它无异常地工作.
你知道为什么吗?在此先感谢您的澄清,

这是方案/项目:Asp.net Mvc 4:

型号/ Ricetta.cs

..
[required(ErrorMessage = "Corpo Articolo vuoto")]
[AllowHtml]
public string corpoTesto { get; set; }
..

Controller / RicetteController.cs

..
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create(Ricettaviewmodel modelloRicetta)
    {
        if (ModelState.IsValid) {
..

查看Ricette / Create从RicetteController中的另一个Action方法调用为View(“Create”,modelObject)

@model WebAPP_MVC4.Areas.Admin.Models.Ricettaviewmodel
 ...
 @using (Html.BeginForm("Create","Ricette",FormMethod.Post)){
 @Html.AntiForgeryToken()
 @Html.ValidationSummary(true)

....

<fieldset>
    <legend>Corpo Ricetta ~</legend>
    <div>
        @Html.LabelFor(p=>p.ricetta.corpoTesto)
    </div>
    <div>
        @Html.TextAreaFor(p=>p.ricetta.corpoTesto,new { @cols = 60,@rows = 20})
        @Html.ValidationMessageFor(p=>p.ricetta.corpoTesto)
    </div>
 </fieldset>
..

解决方法

我做了快速测试,一切正常,Html.BeginForm()和Html.BeginForm(“action”,“controller”)之间的行为没有区别.也许这个问题的原因在于您没有向我们展示的源代码.

在我的代码(工作)下面:
VieModel:

public class Postviewmodel
{
    [AllowHtml]
    [required]
    public string Content { get; set; } 
}

控制器:

public ActionResult Index()
{
    return View("Create",new Postviewmodel());
}

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Postviewmodel model)
{
    if (ModelState.IsValid)
    {
        return Index();
    }
    return View(model);
}

视图:

@model SendHTmlTpControler.Models.Postviewmodel

<html>
<head>
    <script src="~/Scripts/tinymce/tiny_mce.js"></script>

    <script type="text/javascript">
        tinymce.init({
            selector: "textarea",toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
        });
    </script>
</head>
<body>
    <h2>Create</h2>

    @using (Html.BeginForm("Create","Home",FormMethod.Post))
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true)

        <div>
            @Html.LabelFor(model => model.Content)
        </div>
        <div>
            @Html.TextAreaFor(model => model.Content,@rows = 20 })
            @Html.ValidationMessageFor(model => model.Content)
        </div>

        <p>
            <input type="submit" value="Save" />
        </p>
    }

</body>
</html>

asp.net-mvc – 将@ Html.RadioButtonFor设置为默认选中

asp.net-mvc – 将@ Html.RadioButtonFor设置为默认选中

我无法将默认单选按钮设置为“已选中”!
我正在使用@ Html.RadioButtonFor:

<div id="private-user">
    @Html.RadioButtonFor(m => m.UserType,"type1",new { @https://www.jb51.cc/tag/dio/" target="_blank">dio",**@Checked="checked"** }) 1
</div>
<div id="proff-user">
    @Html.RadioButtonFor(m => m.UserType,"type2",new { @https://www.jb51.cc/tag/dio/" target="_blank">dio" }) 2
</div>

是否可以使用@ Html.RadioButtonFor设置单选按钮?

谢谢

解决方法

看看这里 RadioButtonFor in ASP.NET MVC 2或列表 Has anyone implement RadioButtonListFor<T> for ASP.NET MVC?

如果您使用的是Enum,请参阅此答案pass enum to html.radiobuttonfor MVC3

asp.net-mvc-3 – 使用Html.RadioButtonFor和Html.LabelFor为相同的模型,但不同的值

asp.net-mvc-3 – 使用Html.RadioButtonFor和Html.LabelFor为相同的模型,但不同的值

我有这个剃刀模板
<table>
<tr>
    <td>@Html.RadioButtonFor(i => i.Value,"1")</td>
    <td>@Html.LabelFor(i => i.Value,"true")</td>
</tr>
<tr>
    <td>@Html.RadioButtonFor(i => i.Value,"0")</td>
    <td>@Html.LabelFor(i => i.Value,"false")</td>
</tr>
</table>

这给我这个HTML

<table>
<tr>
    <td><input id="Items_1__Value" name="Items[1].Value" type="radio" value="1" /></td>
    <td><label for="Items_1__Value">true</label></td>
</tr>
<tr>
    <td><input checked="checked" id="Items_1__Value" name="Items[1].Value" type="radio" value="0" /></td>
    <td><label for="Items_1__Value">false</label></td>
</tr>
</table>

所以我有ID Items_1__Value两次,当然 – 不好,不工作在浏览器,当我点击第二个标签“假”的第一个广播将被激活。

我知道我可以在RadioButtonFor添加一个自己的ID,并用我的标签来引用,但这不是很好,是吗?特别是因为我在一个循环,不能只使用名​​称“值”与一个添加的数字,这将最终在多个Dom Ids在我的最终HTML标记以及。

应该不是一个很好的解决方案呢?

解决方法

我一直在想如何MVC确定“嵌套”字段名称和ID。它花了一些研究MVC源代码来找出,但我想我有一个很好的解决方案。

EditorTemplates和displayTemplates如何确定字段名称和ID

随着EditorTemplates和displayTemplates的引入,MVC框架添加了ViewData.TemplateInfo,其中包含当前的“字段前缀”,例如“Items [1]”。嵌套模板使用此来创建唯一的名称和ID。

创建我们自己的唯一ID:

TemplateInfo类包含一个有趣的方法,GetFullHtmlFieldId.我们可以使用它来创建我们自己的唯一ID,如:

@{string id = ViewData.TemplateInfo.GetFullHtmlFieldId("fieldName");}
@* This will result in something like "Items_1__fieldName" *@

为了胜利

以下是如何为您的示例实现正确的行为:

<table>
<tr>
    @{string id = ViewData.TemplateInfo.GetFullHtmlFieldId("radioTrue");}
    <td>@Html.RadioButtonFor(i => i.Value,"1",new{id})</td>
    <td>@Html.LabelFor(i => i.Value,"true",new{@for=id})</td>
</tr>
<tr>
    @{id = ViewData.TemplateInfo.GetFullHtmlFieldId("radioFalse");}
    <td>@Html.RadioButtonFor(i => i.Value,"0","false",new{@for=id})</td>
</tr>
</table>

其中将给你以下HTML:

<table>
<tr>
    <td><input id="Items_1__radioTrue" name="Items[1].Value" type="radio" value="1" /></td>
    <td><label for="Items_1__radioTrue">true</label></td>
</tr>
<tr>
    <td><input checked="checked" id="Items_1__radioFalse" name="Items[1].Value" type="radio" value="0" /></td>
    <td><label for="Items_1__radioFalse">false</label></td>
</tr>
</table>

免责声明

我的剃刀语法是欠发达,所以请让我知道,如果这个代码有语法错误。

物有所值

这是非常不幸的,这个功能不是内置的RadioButtonFor。看来逻辑上所有渲染的单选按钮应该有一个ID是它的名称和值的组合,但事实并非如此 – 也许因为这将不同于所有其他Html助手。为此功能创建自己的扩展方法也是一个合理的选择。但是,它可能会棘手使用“表达式语法”…所以我建议重载.RadioButton(名称,值,…)而不是RadioButtonFor(表达式,…)。你可能想要一个.Label(名称,值)的重载。我希望一切都有意义,因为在那一段有很多“填空”。

Button UI Kit CSS3漂亮Button按钮_html/css_WEB-ITnose

Button UI Kit CSS3漂亮Button按钮_html/css_WEB-ITnose





button ui kit



http://www.999jiujiu.com/






















立即学习“前端免费学习笔记(深入)”;

关于html开发日记-form buttonhtml form 教程菜鸟教程的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于asp.net-mvc – Html.BeginForm()工作正常,Html.BeginForm(“action”,“controller”)忽略[AllowHtmlAttribute]、asp.net-mvc – 将@ Html.RadioButtonFor设置为默认选中、asp.net-mvc-3 – 使用Html.RadioButtonFor和Html.LabelFor为相同的模型,但不同的值、Button UI Kit CSS3漂亮Button按钮_html/css_WEB-ITnose的相关知识,请在本站寻找。

本文标签: