简体   繁体   中英

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. How would I know if they checked it or not?

view:

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

controller:

[HttpPost]
public ActionResult Edit(string inputValue, InterviewViewModel model)
{
    if (model.Monday == true)
    {
        return View(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

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. Also you can use @Html.CheckBoxFor(m => m.Monday); so it gets strongly bounded

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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