Telerik mMVC master detail grid view for two unrelated models - asp.net-mvc

I need to display/present two different models in a master-detail grid.
One model(collection) is bound to master grid.It has a link in one of the column and is enabled/disabled based on condition. Simple.
What I need to do is upon clicking the link I should be able to populate the detail grid by calling another controller- action. I need the row information,to pass the row details/ model data to the controller-action to fetch the model for detail grid.How do I do this through Javascript/jQuery.
The detail model is not a collection.
Any other approach to achieve this?

http://demos.telerik.com/aspnet-mvc/razor/grid/detailsajax gives a great example on how to do this with AJAX. I am assuming you are using the MVC Extensions by Telerik?

Related

Concept on displaying cross-table(conjunction) data in ASP MVC

Just a rookie in .NET MVC world and still learning
I created three EF models in framework, one is clients, one is order, and items, below is the relation:
Client Order Items
PK:ID PK Order.id PK Items.ID
... FK:Client.id ...
FK:Item.id
In this case I wanna display all the client information and the item details they've bought in one table, obviously I cannot use any DBcontext here. So what should I do to combine the three table's info and output that? Create a new model on those three?
Any ideas or article are very welcomed!
I would create a ViewModel with all of the Data that you want to display. This is the model that will get populated in the controller and then it would get passed to the View.
So in the View it would use the ViewModel and wouldn't need to know about the underlying Database Model.
And in the Controller you would get the data needed and populate the ViewModel and pass that model onto the View.
Here is a page with an examples. There are plenty more out there too. http://sampathloku.blogspot.com/2012/10/how-to-use-viewmodel-with-aspnet-mvc.html

Creating a model for MVC

I'm building my first MVC project and I have a question about the model.
Each webpage can only contain 1 model, yet my page will require 2 models, one is the search option (the ability to narrow your search such as selecting price range, colour etc) as well as the data.
Is it really as simple as creating a new Model, similar to a ViewModel which in this case would only have 2 properties, a SearchModel and a ProductModel?
Yes, there are really two "models" which is sometimes confusing. There's the "View Model" and the "Domain Model." The view model is passed directly to and from the view. The domain model describes the real-life domain that you're dealing with and is what the database persists. Often, they are the same thing, such as if you're displaying information for a single real domain object (e.g., a car). If you have two domain models that go on one page, you should make a view model with both as properties.
If you are looking to have two models in a view then this question might provide useful information:
multiple-models-in-a-view
Edit:
A good example is the 'Manage' view in the default 'Account' controller of a fresh mvc app. It uses a partial view to handle the changing of a user's password. Whilst both views are using the same model type it shows how to implement a partial view. In this case both the main view and the partial are submitting to the same method on the controller, hence they need to use the same model (which is a parameter for the controller method). But if the partial were to invoke a different controller method then the submitted model could be different. Hope this makes sense :)

Create/Edit Parent and Child Form MVC

I am using C# and MVC3
I have a simple Entity Model
Entities: Orders , OrderItems
Orders have 0 or more Order Items
I want to create a single page to create an order
While on this Page I would fill in the fields that are in the Orders table (Customer, Phone, Order Number...etc)
Then there would be a grid (I am using Telerik MVC grid). I want to add OrderItems to this grid. I was thinking of having s small form above the grid with its own submit button. I can submit using ajax and refresh the grid using ajax.
At the bottom there would be a single submit button that coudl create the order and all the orderitems at once.
I can't seem to piece this enitre solution together.
Short answer: follow this post - how to implement Create action on Order and Order Details on single Create View
Basically, convert your code to partial views in your main view. Also separate order entry form from displaying the order list. Also you may find useful to look at this resource - Empty Model with Partial View

How To: Use MVC and Ajax to add / remove a row in grid for data entry + model binding?

I'm new to Ajax, but I think I know how to reasonably use MVC + model binding.
What I'm trying to do is to create an Add button (or Ajax.ActionLink) to add a new row in my grid for data entry. Example: Think of a typical Order entry system with Order (header) and Product (items). My OrderViewModel contains an "Order" object, and the Order object contains a collection List.
The way I plan to do this is that my View render the grid in a PartialView, and the PartialView is a simple for-loop to create the table tags from the List. I will use the default model binder (for collections).
Anyone have suggestions on how to do this?
I've already figured out how to do this using jQuery, but I want (i think I want) to try and use Ajax so that I can add my custom business logic (e.g. like setting defaults, translations, etc.)as opposed to do this client-side.
In other words, I want to do do something similar to what the Telerik grid does with its Ajax Editing with the Add/Remove link/buttons.
Tips and sample code would be greatly appreciated.
One of my challenges, and not sure if I'm going down the wrong way, is that I don't know how to pass back the model back to the Controller Action from the Ajax submit. When I look at Telerik's code, it looks like they store the persisted items in HttpContext.Session, and this is exactly the reason why I don't want to use their grid.
Thanks.
They might choose the session repository storage for demonstration purposes. If you transform the logic from their SessionProductRepository class for your model and implement identical Update/Insert/Delete methods for it, you'll probably get what you want.

a controller with multiple repositories in ASP.Net MVC 3

I have a controller which controls a view which is a criteria search page. The view has a search criteria section at the top and a grid section at the bottom which will display the results from the search.
I have two repositories in my controller, one for Common stuff like combobox values which is associated with Criteria section. The other repository is for the grid data.
I create a viewmodel with both repositories and pass it to my view (as my model) which makes my Model really huge. Is there any better way of doing this?
It is better to use Unit of Work and Repository

Resources