0

I'm Trying to call Partial View Into view i want to call parameterized method which is returing the partial view so how to call it.

My code is below.

View

@{Html.RenderPartial("~/Views/Appoinment/GetALLAppoinmentMedicine.cshtml",
    new List<HMS.Models.AppointmentViewModel> { new HMS.Models.AppointmentViewModel() }, 
    new ViewDataDictionary { { "aid", Model.AppoinmentIDP} });}

Controller

public ActionResult GetALLAppoinmentMedicine(int aid)
{
    var idParam = new SqlParameter
    {
        ParameterName = "APPIDP",
        Value = aid
    };
    var SpResult = DB.Database.SqlQuery<AppointmentViewModel>("exec uspAppoinmentMedicine_GetAll @APPIDP", idParam).ToList<AppointmentViewModel>();
    IEnumerable<AppointmentViewModel> Result = SpResult.Select(s => new AppointmentViewModel
    {
        MadicineName = s.MadicineName,
        PotencyName = s.PotencyName,
        SizeofPills = s.SizeofPills,
        Dose = s.Dose,
        DoseType = s.DoseType,
        Repitation = s.Repitation,
        Quantity = s.Quantity,
        Duration = s.Duration
    });
    return View(Result);
}
D-Shih
  • 44,943
  • 6
  • 31
  • 51
Azaz khan
  • 34
  • 1
  • 10
  • `RenderPartial()` dos not call a server method. If you want to call your `GetALLAppoinmentMedicine(int aid)` method then you use `RenderAction()` –  Mar 19 '18 at 12:53
  • You can go through link.. https://stackoverflow.com/questions/20799658/how-can-i-pass-parameters-to-a-partial-view-in-mvc-4 Hope it helps.. – nitin pawar Mar 19 '18 at 13:02
  • refer this https://stackoverflow.com/questions/20799658/how-can-i-pass-parameters-to-a-partial-view-in-mvc-4 It works – nitin pawar Mar 19 '18 at 13:08

3 Answers3

1

Try to use @{ Html.RenderAction("ChildAction","Home", new {param="abc"}):

It invokes the specified child action method and renders the result inline in the parent view.

Hope this will work.

Mukesh Kumar
  • 2,354
  • 4
  • 26
  • 37
0

The return type of Html.RenderAction is void that means it directly render the responses in View where return type of Html.Action is MvcHtmlString you can catch its render view in the controller and modified it also by using following method

@{Html.RenderAction("GetALLAppoinmentMedicine", "ControllerName",new {uid= 1})}

If you want to use Ajax.ActionLink, replace your Html.ActionLink with:

@Ajax.ActionLink(
"Partial", 
"GetALLAppoinmentMedicine", 
"ControllerName", 
new AjaxOptions { aid = 1 }
)

and of course you need to include a holder in your page where the partial will be displayed:

<div id="myresult"></div>

Also don't forget to include:

 <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" 
  type="text/javascript"></script>

in your main view in order to enable Ajax.* helpers. And make sure that unobtrusive javascript is enabled in your web.config (it should be by default):

Mysterion
  • 384
  • 4
  • 9
0

You can pass parameter or model as per your need.. dont forget to put the reference to the model in partial view

eg.@Html.Partial("_SomePartial", Model)