1

I'm using ASP NET CORE MVC 5.

I have a View ("ChooseServices") which, depending on the parameter passed, displays 1 or N PartialViews (Forms):

ChooseServices.cshtml:

<div class="col">
    @if (Model.OfferServiceA)
    {
        <partial name="_FormA" />
    }

    @if (Model.OfferServiceB)
    {
        <partial name="_FormB" />
    }

    @if (Model.OfferServiceC)
    {
        <partial name="_FormC" />
    }
</div>

enter image description here

After answering each Form individually, I want to display a default message which is another PartialView ("_confirmation.cshtml") in place of the Form.

Something like this: (after submit Form-A) after submit Form-A

(and after submit Form-C) and after submit Form-C

In summary, after submitting a Form (partial view), I want it be replaced by another PartialViews, all inside the View "ChooseServices".


[EDIT - Some code]


CONTROLLER:

public class SomeServiceController : Controller
{
    // A survey brings to here. 
    public IActionResult ChooseServices(SuggestedServicesDTO dto)
    {
        return View(dto);
    }
}

VIEWS (ignoring css)

ChooseServices.cshtml

@model SuggestedServicesDTO 

<section >
    <div class="container">
        <div class="row">
            <div class="col">

                @if (Model.OfferServiceA)
                {
                    <partial name="_FormA" />
                }

                @if (Model.OfferServiceB)
                {
                    <partial name="_FormB" />
                }

                @if (Model.OfferServiceC)
                {
                    <partial name="_FormC" />
                }
            </div>
        </div>
    </div>
</section>

_Form{x}.cshtml

{x} is the service name.

    <div class="card">
        <div class="card-body">
            <h3>THIS IS THE FORM-{x}.</h3>
            <form asp-action="??IDK what put here">

                <div>
                    <label>Select an option:</label>

                    <!-- Radio buttons Begin --> 
                    <div>
                        <label for="service{x}Opt{N}">
                            <input type="radio" name="optionsService{x}" id="service{x}Opt{N}" value="someValue1">
                            <span>Option QWERTY</span>
                        </label>
                    </div>

                    <div>
                        <label for="service{x}Opt{N}">
                            <input type="radio" name="optionsService{x}" id="service{x}Opt{N}" value="someValue2">
                            <span>Option ASDFGH</span>
                        </label>
                    </div>

                    <!-- others options here --> 

                    <!-- Radio buttons end--> 

                </div>



                <div>
                    <input type="submit" value="Submit {x}"/>
                </div>
            </form>
        </div>
    </div>

_Confirmation.cshtml (Just a message, nothing important)

<div class="card">
    <div class="card-body">
        <div>
            <h3>Thanks for answering!</h3>

            <p>bla bla bla bla</p>
            <button type="button" onclick="window.open('someurl', '_blank').focus();">
                Do something...
            </button>
        </div>
    </div>
</div>

I don't know what to do after submit de Forms{x}.

3
  • Can you show any code in which you've attempted to do this? One idea not know what you are thinking: Wrap each form with a div and give it a unique id. When submitting a Form, use AJAX and capture the wrapper's Id in a variable. Have the AJAX response contain your view. Find the div searching the DOM for the wrapper with the id you captured. Replace that element you find with the response. Commented Aug 12, 2021 at 3:44
  • @AnthonySylvia I edited the post (added some code) Commented Aug 12, 2021 at 5:32
  • Does this post useful to you ? Commented Aug 13, 2021 at 9:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.