0

I have one PartialView that has been Included inside two other views.

How would I be able to pass parameter from PartialView to main Controller of each View.

@Html.Partial("_Video","file1.xml")

and

@Html.Partial("_Video","file2.xml")

I want to be able to get the parameter value on Get method on each controller.

        //Controller1 
        // GET: //
        public ActionResult Index(){
             "file1.xml"
        }

        //Controller2
        // GET: //
        public ActionResult Index(){
             "file2.xml"
        }

1 Answer 1

1

Just been solving this problem myself so hope it helps you.

In your view cshtml:

@Html.Action("_Video", "Controller1", new { paramValue = "some string" } )

You'll need to create a partial view named "_Video.cshtml" in this case (defining the correct model type via the @model directive) and in your controller:

[ChildActionOnly]
public ActionResult _Video(String paramValue) {
   // paramValue == "some string"
   // .. do something with aModel ...
   return PartialView(aModel);
}

However, if you're wanting to return xml or similar data content check that a view model container, Web Api or RESTful data calls aren't better fits (search on the "Json()" function if you're calling from client script too).

HTH

Sign up to request clarification or add additional context in comments.

Comments

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.