The thing is there is no RenderAction in .net core (in contrary of netframework)
if there was RenderAction I could easly create a Model in Controller. But I am using RenderPartial now and got partial view directly without manuplating by controller.
that means I have to have 2 code parts that I need to constantly change and make similar
that doubles my job
We can only see the code that you provide. If you are looking for an alternative solution then you need to tell us.
fatihbarut
that is why I am here to ask the other solution
Use standard MVC and coding patterns.
Most likely the partial view is not needed. I would remove the partial and just use a regular view. You can always refactor the code to include the partial at a later time.
Execute the query in the controller or business layer not in a Partial View. Build a ViewModel that tells the View how to render. For example, return a "Strongly Typed Create View" (from the action) if the query returns an empty result set.
You'll need to clarify your requirements if you need further design assistance.
Member
92 Points
534 Posts
How to show a PartialView with Model "With null model"
Mar 26, 2019 10:00 AM|fatihbarut|LINK
Hi all,
I have a PartialView which I want to show in a View like the below code and I want to show it empty at the load of the page (View).
Then using Jquery I will call it again and fill it when ever I need.
Could you help me please without having error that Model is not exist or null or something.
I have
All-Star
53121 Points
23675 Posts
Re: How to show a PartialView with Model "With null model"
Mar 26, 2019 12:06 PM|mgebhard|LINK
Add a conditional statement but you'll need to execute the query first.
I recommend that you pass a model to PartialView rather than a query.
Untested
Member
92 Points
534 Posts
Re: How to show a PartialView with Model "With null model"
Mar 26, 2019 12:14 PM|fatihbarut|LINK
that is not the solution.
I need to show "empty" version of the elements therefore I kinda need
create an empty Model and show its fields empty (if the model is empty).
All-Star
53121 Points
23675 Posts
Re: How to show a PartialView with Model "With null model"
Mar 26, 2019 12:22 PM|mgebhard|LINK
Add and else to the condition and render HTML inputs as needed.
Member
92 Points
534 Posts
Re: How to show a PartialView with Model "With null model"
Mar 26, 2019 01:34 PM|fatihbarut|LINK
it is not the solution
that means I have to have 2 code parts that I need to constantly change and make similar
that doubles my job
that is why I am here to ask the other solution
Member
92 Points
534 Posts
Re: How to show a PartialView with Model "With null model"
Mar 26, 2019 02:03 PM|fatihbarut|LINK
The thing is there is no RenderAction in .net core (in contrary of netframework)
if there was RenderAction I could easly create a Model in Controller. But I am using RenderPartial now and got partial view directly without manuplating by controller.
All-Star
53121 Points
23675 Posts
Re: How to show a PartialView with Model "With null model"
Mar 26, 2019 02:07 PM|mgebhard|LINK
We can only see the code that you provide. If you are looking for an alternative solution then you need to tell us.
Use standard MVC and coding patterns.
Most likely the partial view is not needed. I would remove the partial and just use a regular view. You can always refactor the code to include the partial at a later time.
Execute the query in the controller or business layer not in a Partial View. Build a ViewModel that tells the View how to render. For example, return a "Strongly Typed Create View" (from the action) if the query returns an empty result set.
You'll need to clarify your requirements if you need further design assistance.