I want to send a string parameter from View that uses partial View to the partial view.
Example: I want to be able to, from the view, create call on partial view and send the string created into the partial view.
Can i do that?
I want to send a string parameter from View that uses partial View to the partial view.
Example: I want to be able to, from the view, create call on partial view and send the string created into the partial view.
Can i do that?
If I understand correctly all you're saying is that you want to be able to pass a parameter from a View to a Partial view inside ?
Yes you can.
You can simply call
@{Html.RenderAction("ActionMethodName",new {parameterName = value})}
OR if you need extra processing to the passed in variable to can pass it through an action method.
1) Create your View ( Let's call it "User" for the sake of example )
2) Create a partial View ( lets call it "_UserInfo" for the same of example)
3) Create an Action method that will return "_userInfo" partial view to your Parent User view and where you're going to pass the string to:
public PartialViewResult UserInfo(string userName)
{
return PartialView("_UserInfo",userName);
}
4) So now, in order to pass a string you can simply add this to your main View: @Model User
@{Html.RenderAction("UserInfo","ControllerName",new {userName=Model.UserName}} //Note that the parameter name has to match with the parameter name you're receiving at the Action Method (UserInfo method above ). It has to be reflected in routing as well.
p.s. This question was asked many times before. Take a look at the following question for example: passing parameters to my partial view?
render a partial view by calling an action which returns partial view
@Html.RenderAction("actionName", "controllerName", new {parameterName= value});