2

I'm trying to load a partial view with Id parameters inside "Bootstrap Model"

I can't pass the parameters to the controller

Something like this:

<td>
    <button class="btnShowModal btn btn-primary btnWhiteSpace " type="button">
        Details
        <i class="fas fa-info-circle" aria-hidden="true"></i>
    </button>
</td>

<div class="modal fade" tabindex="-1" id="loginModal"
     data-keyboard="false" data-backdrop="static">
    <div class="modal-dialog modal-sm ">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <i class="fas fa-window-close"></i>
                </button>
                <h4 class="modal-title"> Title</h4>
            </div>
            <div class="modal-body ">
                <partial name=("bid", "details" asp-route-id="item.QuettaReqId" ) />
            </div>
        </div>
    </div>
</div>

The error I'm getting is:

InvalidOperationException: The partial view '(' was not found. The following locations were searched:
Views/Mail/(.cshtml
/Views/Shared/(.cshtml
/Pages/Shared/(.cshtml

It look like routing but I think that the parameter is set also not being pass as should.

1
  • Your partial is not well-formed. Is your intention to load a partial view called "bid"? And are you trying to do some logic when you load the view? Commented Oct 15, 2018 at 5:36

3 Answers 3

4

For passing item.QuettaReqId from Main view to partial view, you need to specify the right Partial View Name and model.

<div>
     <partial name="_Details" model="10"/>
     @await Html.PartialAsync("_Details", 5)
</div>

For _Details, you need to define @model to accept the parameter.

@model int

This is Detail View with Id @Model

Note, _Details is the Partial View Name.

For more information about model, check model

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

1 Comment

He said : I can't pass the parameters to the controller. Your solution passing parameter as model to the view. What if I have complex model along some parameters needs to be passed to the view?
2

Try this:

@{ Html.RenderAction("YourActionName", "ControllerName", new { parameterName = parameterValue });}

So in case of you as follows:

<div class="modal-body ">
  @{ Html.RenderAction("details", "bid", new { id= item.QuettaReqId});}
</div>

Now if you want a ASP.NET Core specific solution then you can use View Components which is much more faster than Partial View.

Comments

-1

The error you are getting because asp.net engine is unable to find the view

You ma replace it with

@Url.Action("YourActionMethod", "Controller", new { param = "1", param2= "2" })

4 Comments

Thanks , but it is just give me a string insite my div model and not load the view @Url.Action("Details", "bid", new { @id= item.QuettaReqId })
@Html.Partial("_SomePartial", new ViewDataDictionary { { "id", someInteger } });
ViewDataDictionary Look like is not fit html helper > @Html.Partial("Details", "bid",Model. new ViewDataDictionary { { "id", item.QuettaReqId } });
You can visit helpmepal.org. They will connect you using teamviewer & help you out

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.