MVC loading multiple partial view dynamically - asp.net-mvc

I want to load partial view dynamically as below sample then i want call specified record with id.I can load partial view dynamically use #Html.Partial() but same partial view returns only first record due to disuse id.How can i solve this issue?
HtmlContent?id=1
Gallery?id=3
ContactForm
HtmlContent?id=5

Related

Model Validation On Nested View

I have a view , data listing in this view . When user select a row , form posting to ajax action and this action returns the row details to partial view.
User doing arrangements the row details and submit form to another action.Model validating at this action and i must return model errors to validatesummary.
But i could not this becouse if i add the model error and return partial view, my main view of course does not showing and only shows partial view.
I want add model error to partial view inside the view. How to fix this ?
replace your data list (or the grid) ourside the <form></form> or #html.BeginForm(){}.
Then the problem will be solved

Update div in different controller with g:formRemote Grails

I have a template that I want to reuse in another view. The template contains a table view. The table view is totally editable. When I edit the table view, it makes calls back to a controller and re renders the tableview, using a g:formRemote tag. I want to use the same template with the same g:formRemote tag in a different controller/view. My issue is that the new template won't re-render. Any tips or suggestions?

Both create and list in the same view MVC4?

I am new to MVC4. I know basic CRUD functionality in MVC, but how can I achieve both create and list in the same view? Like after a user creates data the user will automatically be redirected to the same view and view the list of data.
You may use partial views to accomplish this. Create the create / edit pages the same way as you do and below the form you may render a partial view that would render the list with even edit / delete buttons.
Alternatively, you may pass both the form data (in case of edit) and the list data to a view to render there.
I would suggest you to use the partial views approach as it would simplify the view and the partial view can be reused on some other page also.
Please take this as a starting point and not as a follow-it-blindly solution.

ASP.NET MVC loading multiple partial views into a single div using JQuery

I am working on a help page which is composed of a navigation tree, content box, and search box. The navigation tree has links to Frequently Asked Questions and Glossary, each of which are linked to an Action which return partial views.
To the right of the navigation tree I have a single content div that I would like to contain whichever partial view is selected in the navigation tree.
Success case (what I want to accomplish): clicking on one of the FAQ links calls the FAQ() method in my controller, then returns a partial view which is then displayed in my content div to the right of the navigation tree. Clicking on another item would cause another partial view to be loaded.
How do I go about this? I've read a ton of ASP.NET MVC JQuery loading blog posts and tutorials but can't find anyone who's done exactly this.
Many thanks!
You should be able to use the jQuery method .load() to load HTML into your div.
http://api.jquery.com/load/
You can create an action that returns the partial view as HTML.
ASP.NET MVC Returning Partial View as a full View Page
jQuery:
one easy way you can do is load all partial views in "Container Div" at page load in one go (if performance is not a issue)
then assign each partial div with different div id inside "container", than use jquery to control show(); hide(); for each div.
MVC:
however if i were you, "Glossary" and "FAQ" looks same model to me it shouldn't be put in different partial view in first place.
if they did designed in separate model, in this scenario, i would recommend you to create a proxy class as a ViewModel above models you want to display, and then load it with one partial view only

ViewData not inheriting in partials

I was trying to use a shared partial view to render when a particular listing page has no data. I wanted to use ViewData to pass information from the page into my listing control, which would then conditionally render the NoData partial view using the ViewData values.
I would like to be able to specify them in the view markup, not in the controller action, but when I add them in the view the don't seem to inherit down into child partial views (like the Nodata partial view). However, specifying them in the ViewData values in the controller actions works fine, the data is available all the way down...
Does anyone know why it behaves this way?
When rendering a partial you can also pass the ViewData.
<% Html.RenderPartial("NoData", ViewData); %>
<%Html.RenderPartial("partialViewName", "viewData", "model"); %>
it is a best practice to do the decision inside the controller, if you have a scenario to make a decision inside the view, separate them and call them inside the controller conditionally

Resources