English 中文(简体)
ASP.net MVC3从超文本中获取核对箱值
原标题:ASP.net MVC3 getting checkbox value from HTML form

我在MVC3网站上有一个简单的表格,使用户能够创建竞争条目。 这一做法已经实施,目前正在实施罚款,但现已要求用户允许其条目为私人条目。

在我的入门模式中,我增加了一个养牛羊。 然后,我图示我会改变制作和编辑的超文本格式,以包括一个检查箱,具体说明该条目是否为私人。

I m new to MVC3, 但我的数字是,我可以简单地改变组成员额的行动,把新的蓝色参数包括在内。

不幸的是,这似乎并未奏效。 谁能告诉我,检查箱的数值如何从超文本转换到邮局行动? 这可能相当常见,但我似乎无法在网上找到这方面的榜样。 几乎所有例子都简单地显示案文投入,但我看不到任何检查箱。

表格:

        <form method="post" action="../Entry/Create" enctype="multipart/form-data" onsubmit="return isValidInput()">
            <input type="text" id="EntryTitle" name="EntryTitle" />
            <div id="invalidTitle" class="invalidData"></div>
            <p id="char-remaining">(100 characters remaining)</p>

            <input type="text" id="EntryVideo" name="EntryVideo" />
            <div id="invalidVideo" class="invalidData"></div>
            <p id="vid-desc">(URL of the Video to Embed)</p>

            <input type="file" id="ImageFile" name="ImageFile" />
            <div id="invalidImage" class="invalidData"></div>
            <p id="file-desc">(200x200px, jpeg, png, or gif)</p>

            <textarea id="EntryDesc" name="EntryDesc"></textarea>
            <div id="invalidDesc" class="invalidData"></div>
            <br />

            <input type="checkbox" id="isPrivate" name="isPrivate" />
            Make my entry private.

            <br />

            (private entries will only be viewable by you and site administrators)

            <br />


            <button id="new-entry-save">save</button>
        </form>

行动:

public ActionResult Create(string EntryTitle, string EntryVideo, HttpPostedFileBase ImageFile, string EntryDesc, Boolean isPrivate)
{
...
}
最佳回答

添加价值=“真实”,以检查箱,在箱子上添加具有相同名称和价值的信息,即:

<input type="checkbox" id="isPrivate" name="isPrivate" value="true" />
<input type="hidden" name="isPrivate" value="false" />

如果你不想使用隐蔽器,则使用ool? 而不是ool(例如,无用)

问题回答

另一种选择是,以同样的名称隐藏案文领域,把未加检查的实地数据作为员额的一部分。 见。 张贴没有检查的检查箱。

<form> 
  <input type= hidden  value= 0  name= selfdestruct > 
  <input type= checkbox  value= 1  name= selfdestruct > 
</form> 




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签