简体   繁体   English

如何从视图/模型向 controller 发送数据

[英]how to send data to controller from view/model

I have a list of dates (mon-fri) that a user can click on a checkbox (What I am showing below is for Monday)我有一个用户可以单击复选框的日期列表(周一至周五)(我在下面显示的是周一)

I'm very new to asp.net and C# so I'm not really sure if this is the correct implementation,... I still don't know how to retrieve the data from the user clicking the checkboxes.我对 asp.net 和 C# 非常陌生,所以我不确定这是否是正确的实现,......我仍然不知道如何从用户点击复选框检索数据。 How would I know if they checked it or not?我怎么知道他们是否检查过?

view:看法:

@Html.Label ("M")
@Html.CheckBox("Monday", false, new { @class = availability" } )

controller: controller:

[HttpPost]
public ActionResult Edit(string inputValue, InterviewViewModel model)
{
    if (model.Monday == true)
    {
        return View(model);
    }
}

model: model:

public class InterviewViewModel
{    
    public bool Monday { get; set;}
}

i am not sure how to know if Monday has be been 'checked' by the user?我不确定如何知道用户是否“检查”了星期一? Also not sure if my implmentation of controller is correct也不确定我对 controller 的实施是否正确

Looks like your implementation should working, Are you submitting the form or not?看起来您的实现应该可以工作,您是否提交了表单? Check if you submit the correct Boolean value gets bind to the model or not in debug mode.检查您是否提交了正确的 Boolean 值绑定到 model 或未处于调试模式。 Also you can use @Html.CheckBoxFor(m => m.Monday);您也可以使用@Html.CheckBoxFor(m => m.Monday); so it gets strongly bounded所以它变得有界

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM