发布结果时复选框MVC 4检查 [英] Posting results when checkbox is checked in MVC 4

查看:115
本文介绍了发布结果时复选框MVC 4检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直要求重新发布这个问题更多的细节。

I've been asked to repost this question with more detail.

我是新来的MVC和我最好的AP preciate任何证明的解释虽然我在.NET开发相当接地。

I'm new to MVC and I'd appreciate any supporting explanations although I am quite grounded in .NET development.

场景

我有一个职位与信息的日历时它的选择日历。它看起来是这样的:

I have a calendar that posts to a calendar with information when it's selected. It looks like this:

@foreach (var OfflineCalendar in Model.OfflineCalendars.Skip(1))
{
    <li data-name="@OfflineCalendar.Name" data-val="@OfflineCalendar.Id">@Html.ActionLink(OfflineCalendar.Name, "Index", new { Id = OfflineCalendar.Id }, new { @class = "location" })</li>
 }

日历仅用于其中的一些数据传送到一个​​ContentResult类型方法每月返回数据。

The calendar only returns data for a month which passes some data to a ContentResult method.

我添加了一个复选框归档数据。

I've added a Checkbox for archived data.

<label>
    Archived
    @Html.CheckBox("checkedArchive")
</label>

我的任务

我要添加存档按钮,用户可以在其中查看历史数据。如果这个复选框被选中,它改变了ContentResult类型数据的方法的一些参数。

I want to add an archived button where a user can view historic data. If this checkbox is checked, it changes some parameters in the ContentResult Data method.

的困境

在.NET中我会轻松地检查一个复选框是否被选中,并触发基于的所选的日历事件。我竭力做MVC等同。

In .NET I would easily check for whether a checkbox is checked and fire an event based on the calendar that's selected. I'm struggling to do the MVC equivalent.

所有我想要做的,如果它在选择一个日历位置的检查就是检查。如果是,返回true或false布尔。这会影响ContentResult类型。

All I want to do is check if it's checked WHEN a calendar location is selected. If it is, return a bool of true or false. Which will affect the ContentResult.

我不希望使用Ajax。我只是单纯的想检查时,选择的地点是否被选中的复选框。就这样。

I don't want to use Ajax. I just simply want to check whether a checkbox is checked when a location is selected. That's all.

下面是相关的问题,我问:<一href=\"http://stackoverflow.com/questions/23214586/checking-if-checkbox-is-checked-in-mvc-4-without-a-submit-button?noredirect=1#comment35514265_23214586\">clicky

Here's the related question I asked: clicky

感谢您的阅读。

推荐答案

这听起来像你想通过你现有的code做所有这些服务器端的,只是要访问的复选框的值。

It sounds like you want to do all of this server side through your existing code and just want to access the value of the checkbox.

如果这是正确的,我将修改视图模型包括一个布尔IncludeArchived,然后将其添加到您的网页:

If that is correct, I would modify the ViewModel to include a boolean "IncludeArchived" and then add it to your page:

 @Html.CheckBoxFor(model => model.IncludeArchived)

当您提交表单的价值应包括在模型中。

When you submit your form the value should be included in your Model.

另外,你可以检查的Request.Form [checkedArchive]在服务器端,并解析成一个布尔值。

Alternatively, you could check Request.Form["checkedArchive"] on the server side and parse that into a boolean.

这篇关于发布结果时复选框MVC 4检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆