0

I want to do something like this; - I'll send a Post request to an action(partial view or something else, i don't know) method with javascript. - Before this action will show me a partial view. - Partial View will also have a form and the user will enter data. - Finally, I will send this data back as the JSON data of my javascript post request.

[HttpPost]
    public ActionResult GetInformation()
    {
        // The ShowForm method returns Partial View, I know.
        // But how do I get and return the data entered in PartialView?
        var data = ShowForm();

        return Json(data);
    }

    public PartialViewResult ShowForm()
    {
        .....
        return new PartialViewResult(); 
    }

As above I want a method of returning JSON data. However, I need to add the PartialView image to the Html page with C #. Then I have to take the data from the form and return it as json.

Can something like this be done? I know my samples can be ridiculous. Because I had no idea.

2
  • In ShowForm: TempData["data"] = data; In GetInformation: var data = TempData["data"] ; Commented Dec 19, 2019 at 1:22
  • The way i would do that would be is i will use a Bootstrap Modal and then inject the partial view in the body section(where it will only be used as a structure) of the modal and validate it on the button click of the modal. By this approach, your data will still be in a single controller's context and you don't need to call the partial view from server-side(controller side). Commented Dec 19, 2019 at 5:45

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.