I am new to MVC architecture. I want to display MVC grid on my page but through databinding.
So currently in my controller I have created a list which I am returning to View.
Dim lst As New List(Of Employee)
.
.
Return View(lst)
In my View I have this code -->
#code
#Html.Grid(Model).Named("grdGrid").Sortable(True).Columns(Function(col) col.Add(Function(o) o.Id)).Columns(Function(col) col.Add(Function(o) o.EmpName))
End Code
So here I am able to display the grid correctly.
On similar basis, is it possible to databind the grid?
If I am getting my code in a data table, and that data table I want to directly bind to my MVC Grid. I do not want to use list.
Thanks
Amruta
Please refer to this blog post to render the pages with partial view.
Posting a link because there might be many pros & cons in your code but you'll get better idea from the link I posted.
Related
Good morning, i have a view that is connected to a view model, it has 3 parts a general information that is a simple model, a address model that is a List<> and a telephone model that is a list too, on the view model. My problem is that on the new customer view, the above view, the address and telephone model is empty, when i give the user the opportunity to add address and telephone the model is empty, so when i need to fill 2 dropdownlists with the above data the page is already loaded. So my question is how can i "refresh" the dropdownlist data to fill from a ViewBag that holds the above data?
Thanks in advance
When the user clicks on the Add New Address button you could perform an AJAX call to a controller action that will return a partial view containing the template of an address that will get added the DOM. Steven Sanderson illustrated the concept in his very excellent Editing a variable length list in ASP.NET MVC blog post.
As an alternative to using AJAX you could also do this using a pure client side approach. For example you could use a templating javascript framework such as knockoutjs. Steven Sanderson also covered this approach in his blog post.
I m working on asp.net mvc application.
i have one partial view in that one submit form and click on submit button than data will stored in database.
but when i get data from form collection than that form collection come null so how can i get partial view control's value in action method?
thanks in advance..
note : partial view is not strongly type.
I think you encounter the same issue that is discussed here:
ASP.NET MVC partial views: input name prefixes
To quickly investigate the issue, look at the source code of your page: do your controls from partials have the names you expect? If not, the article above will be helpful.
I need a Source Code for Calling Multiple in ASP.NET MVC 2.0(ASPX Engine) Actions on a Link which is bound to Telerik MVC Grid Column.
I am using Entity Framework , Linq to Entities , ASP.NET MVC 2 , Repository pattern and ASPX ViewEngine .
I have a Telerik MVC Grid Column as Status . This column is bound to a ClientTemplate ( ActionLink Format) as " View " . When a user clicks on " View " .
Multiple Telerik MVC Grids which showing
1. Problem Log . ( Visible only if Status is " Account is in Error" otherwise show last Cleared Problem ( Problem text and Problem Description coming from DB, Can be shown only in a TextBox(problem Name,) " In error" and a div " description of Problem" )
Status History .
Bank account information for logged User
Admin Information
should be displayed ..
from Status Grid Column I am fetching a Bank Account Number and my Status is coming from another table ..
now my problem is that how to call multiple actions present in my controller ( with conditions ) ?
Can anybody guide me with working code if any ?:(
if possible mail me on ashes22#gmail.com
When view is clicked you want to show a new view that contains then calls to other action methods in your controller(s) or other views.
So for example when you click on the View link on the grid, you would then have the view link go to another Route (and in turn another controller).
So lets say the "view" link brings you to a controller named
CombinedStatusController
Then in your /Views/CombinedStatusController/Index.aspx
you call RenderAction to call a method on each controller here Im assuming named StatusController, BankAccountController, AdminInformationController each with a method:
public ActionResult Index(int statusId)...
<%=Html.RenderAction("Index", "Status", new { statusId = statusId} ) %>
<%=Html.RenderAction("Index", "BankAccount", new { statusId = statusId} ) %>
<%=Html.RenderAction("Index", "AdminInformation", new { statusId = statusId} ) %>
Each one of those actions would then return a view with a telerik grid in it.
So you have three separate views that are getting created by calling one parent view of CombinesStatusController.
Now - another option instead of Html.RenderAction is Html.RenderPartial. The difference is RenderPartial goes directly to a view (without going through your controller) and passes over a copy of the current model to it. In your case you need to retrieve data specific to a statusId so I would not use RenderPartial here but RenderAction.
Hope this helps a bit : )
You don't call multiple Actions from the front-end. You call one and have that one call other Action (or non-Action) methods within the Controller.
I have an MVC application. Say for example if we have a dropdown Cars makes which when selected posts to itself and gets Car Models. Now on post, the field Car makes loses it value. I am using Form.Get("combo_box_field_name") and if it has a value I am prepopulating the car make dropdown. As lot of controls on my form do this sort of post and i have to prepopulate the fields , I was wondering if this is the right way of doing stuff. I have done loads of asp classic works and also asp.net and looks like mvc is very similar in approach tp classic asp. If someone can guide in in the right way this can be handled it would be greatly appreciated.
I am not looking to use AJAX so pls dont tell me with regard to cascading dropdowns and I have a host of other controls in the form which will need updating on the form being posted to itself before I leave the page to save the data
I don't think I've ever used Form.get in my MVC application.
I post back to the controller which looks like;
[AcceptVerbs(HttpVerbs.Post), Authorize]
public ActionResult MyAction(FormCollection collection)
{
MyClass myClass = new MyClass();
UpdateModel(myClass);
//do stuff with data
return View(myClass);
}
So basically you're letting MVC grab the data from the view for you.
You may need to reload your dropdown lists with this but you can get around that by using JSON to do partial postbacks.
I am building a site in ASP.NET MVC. I intend to replicate the way StackOverflow displays its posts. Are these guys using a repeater control in ASP.NET MVC?
I do want complete control on the markup rendered, but I also want pagination.
What is the best approach in such a case.
I have no idea how StackOverflow implements it, but you don't need to use any asp.net control.
Of course you would need to build your own pager.
Take a look at the NerdDinner tutorial, it has a section showing how you can create a paged list.
http://weblogs.asp.net/scottgu/archive/2009/04/28/free-asp-net-mvc-nerddinner-tutorial-now-in-html.aspx
It is pretty easy and you have full control over all the markup. In fact you pretty much have to provide all the markup almost none of the markup is generated by asp.net.
In MVC, I would suggest using a combination of a LINQ query in your controller (or in a repository, within a function called from the controller), a for loop in your view, and depending on on how complex the items you want to display are, a partial view inside the loop.
For pagination, you might pass start and count parameters to a function to get a section of a list of objects via LINQ. For example:
Function sliceList(ByVal startIndex As Integer, ByVal count As Integer) As Generic.List(Of myObject)
Dim FullObjectList As Generic.List(Of myObject) = GetObjectsFromSomewhere()
Dim returnList As New Generic.List(Of myObject)
returnList = From o In FullObjectList Skip startIndex Take count
Return returnList
End Function
Then your controller passes the returned listed to the view for display, and you loop through it, displaying the items however you please.
Hope this helps.