您最好的选择是搜索更新的问题,或搜索下面的答案,寻找您的MVC的特定版本,因为现在许多答案已经过时.
如果您确实找到适合您的版本的答案,请确保答案包含您正在使用的MVC版本.
(原始问题从下面开始)
这对我来说似乎有点奇怪,但就我所知,这就是你如何做到的.
我有一组对象,我希望用户选择其中一个或多个.这对我说"形式有复选框".我的对象没有任何"选择"的概念(它们是通过反序列化wcf调用形成的基本POCO).所以,我做了以下事情:
public class SampleObject{
public Guid Id {get;set;}
public string Name {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
在视图中:
<%
using (Html.BeginForm())
{
%>
<%foreach (var o in ViewData.Model) {%>
<%=Html.CheckBox(o.Id)%> <%= o.Name %>
<%}%>
<input type="submit" value="Submit" />
<%}%>
Run Code Online (Sandbox Code Playgroud)
并且,在控制器中,这是我可以看到用来检查用户检查的对象的唯一方法:
public ActionResult ThisLooksWeird(FormCollection result)
{
var winnars = from x in result.AllKeys
where result[x] != "false"
select x;
// yadda
}
Run Code Online (Sandbox Code Playgroud)
它首先是怪异的,其次,对于用户检查的那些项,FormCollection将其值列为"真假"而不仅仅是真.
显然,我错过了一些东西.我认为这是基于这样的想法构建的,即在html表单中作用的集合中的对象是使用UpdateModel()或通过ModelBinder 更新的.
但我没有为此设置对象; 这是否意味着这是唯一的方法?还有另一种方法吗?
我对Google Chrome及其表单自动填充功能存在设计问题.如果Chrome记住某些登录名/密码,则会将背景颜色更改为黄色.
以下是一些截图:

如何删除该背景或只是禁用此自动填充?
当我点击重置按钮时,我有可以重置表单的工作代码.然而,在我的代码变得越来越长之后,我意识到它不再起作用了.
<div id="labels">
<table class="config">
<thead>
<tr>
<th colspan="4"; style= "padding-bottom: 20px; color:#6666FF; text-align:left; font-size: 1.5em">Control Buttons Configuration</th>
</tr>
<tr>
<th>Index</th>
<th>Switch</th>
<th>Response Number</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<form id="configform" name= "input" action="#" method="get">
<tr><td style="text-align: center">1</td>
<td><img src= "static/switch.png" height="100px" width="108px"></td>
<td id="small"><input style="background: white; color: black;" type="text" value="" id="number_one"></td>
<td><input style="background: white; color: black;" type="text" id="label_one"></td>
</tr>
<tr>
<td style="text-align: center">2</td>
<td><img src= "static/switch.png" height="100px" width="108px"></td>
<td id="small"><input style="background: white; color: black;" type="text" id = "number_two" value=""></td>
<td><input …Run Code Online (Sandbox Code Playgroud) 使用GET或POST方法有什么区别?哪一个更安全?他们每个人的(dis)优势是什么?
(类似问题)
假设我们正在使用AngularJS构建一个地址簿应用程序(人为的例子).
我们有一个联系人表单,其中包含电子邮件和电话号码的输入,我们想要一个或另一个,但不是两个:我们只希望输入为空或无效时email需要phone输入,反之亦然.
Angular有一个required指令,但从文档中不清楚如何在这种情况下使用它.那么我们如何才能有条件地要求表格领域呢?写一个自定义指令?
我有一个输入:
<input type="text" id="name" class="form-control" name="name" v-model="form.name" :disabled="validated ? '' : disabled">
Run Code Online (Sandbox Code Playgroud)
在我的Vue.js组件中,我有:
..
..
ready() {
this.form.name = this.store.name;
this.form.validated = this.store.validated;
},
..
Run Code Online (Sandbox Code Playgroud)
validated作为a boolean,它可以是0或者1,但无论数据库中存储了什么值,我的输入始终被禁用.
我需要禁用输入false,否则应启用并可编辑.
更新:
这样做总是启用输入(无论我在数据库中有0还是1):
<input type="text" id="name" class="form-control" name="name" v-model="form.name" :disabled="validated ? '' : disabled">
Run Code Online (Sandbox Code Playgroud)
这样做总是禁用输入(无论我在数据库中有0还是1):
<input type="text" id="name" class="form-control" name="name" v-model="form.name" :disabled="validated ? disabled : ''">
Run Code Online (Sandbox Code Playgroud) 我有一个表单输入元素,并希望更改其title属性.这必须很容易,但由于某种原因,我找不到如何做到这一点.这是怎么做的,我应该在哪里以及如何搜索如何做到这一点?
我有一个旧的Web应用程序,我必须支持(我没有写).
当我填写表格并提交然后检查Chrome中的"网络"标签时,我会看到"请求有效负载",我通常会看到"表单数据".两者之间有什么区别,何时会发送一个而不是另一个?
谷歌搜索这个,但没有找到任何解释这个的信息(只是人们试图让javascript应用程序发送"表单数据"而不是"请求有效负载".
forms ×10
html ×3
post ×3
checkbox ×2
css ×2
http ×2
javascript ×2
jquery ×2
angularjs ×1
asp.net-mvc ×1
attributes ×1
autofill ×1
element ×1
get ×1
http-method ×1
icons ×1
input ×1
php ×1
reset ×1
rest ×1
validation ×1
vue.js ×1