lundi 30 janvier 2017

Calling jQuery code in razor block of code

I have a problem where I need to call jQuery code to fetch a value from an HTML element like following:

@using (Html.BeginForm("Login", "Home",new { Checked = $('#checkbox5').checked }, FormMethod.Post,new { @class = "form-horizontal", role = "form" }))
{  
@Html.AntiForgeryToken()  
}

Note that besides passing the entire model into my Login action I'm trying to pass an optional parameter named "Checked". This parameter basically states whether the "remember me" checkbox has been checked on the form or not.

The checkbox itself is not the one that .NET uses by default like:

@Html.CheckboxFor(somepropertyhere);

But instead a regular checkbox like this:

   <input id="checkbox5" type="checkbox">
     <label for="checkbox5">
     Remember me?
     </label>

How can I fetch this checkbox's value when passing it as an extra parameter besides my model?

So that my method in the end would look like:

Public ActionResult Login(bool Checked, LoginViewModel model)
{
// To have the checked value here now...
}

P.S. And I can't use Html.CheckboxFor for some reasons, but I don't wanna get too much into details since the question wouldn't make sense then (maybe it doensn't even now I'm not sure if this is doable what I'm trying to achieve).

Can someone help me out?




Aucun commentaire:

Enregistrer un commentaire