Edward Sheriff Curtis
Edward Sheriff Curtis

Reputation: 497

How can i open a new webpage after i click a checkbox

How can I open a new web page after I click a checkbox using c# asp net MVC ?

I need open the new view Index_p when selected checkbox Breakfast in the view Index

My view Index

<div class="row">
    <div class="col-md-12">
        <div class="form-group" style="background-color: darkorange; border:3px solid; font-weight:bold;">
            <h5 style="font-weight: bold;"> Breakfast: @Html.CheckBoxFor(m => m.Breakfast, true) </h5>
        </div>
    </div>
</div>

My model:

public class PersonModel
{
    public bool Breakfast { get; set; }
}

My controller:

[HttpPost]
public ActionResult Index(PersonModel person)
{
    bool ischecked = person.Breakfast;

    if(ischecked == true)
        return RedirectToAction("Index_p");

    if (ModelState.IsValid)
    {
        return View(person);
    }
}

Upvotes: 0

Views: 45

Answers (1)

Rahul Shukla
Rahul Shukla

Reputation: 716

Below is the updated code, RedirectToAction only when you are trying to redirect to action method not view.

if(ischecked == true)
    return View("Index_p");

if (ModelState.IsValid)
{
    return View(person);
}

Upvotes: 1

Related Questions