Replicating web form in MVC 4 - asp.net-mvc-4

I'm very new to MVC, but I get the general concept.
However, I'm stuck trying to replicate a page that was very easy to create in web forms.
In web forms, I have a dropdownlist (Majors), that when selected, does a postback and displays a listbox (Courses) based on the value from the DDL.
Then, when an item from the listbox is selected, another postback occurs and a grid (Classes) is displayed based on the item from the listbox.
During the postbacks, the selected items in the DDL and Listbox stay selected.
In my attempt at this in MVC, I've got spaghetti code all over...
My question is, can I accomplish this, with one Controller, one View, and three Partial Views? I just want to stick with plain MVC, I can work in the jQuery once I get it working.

You have to load up the Dropdowns and have model for real record on page so that there is alt least 3 models..... so you will have to use a Viewmodel to bring all 3 models together
So do up your model classes for Classes\course\Main model (Student?) then create a viewmodel for all 3
Then your view has access to viewmodel and all classes/data

Related

How to prevent required validation on a read only form in .NET Core Razor pages

I have a read only form where it's only function is to search on the provided parameter and populate the form with the results, I am binding it to a model but the model uses the Required data annotation and when I click the search button, the ModelState.IsValid is false, when I checked to see which property it's complaining about, I found it's not even one I'm using on the form so because I also use this model for insert and updates and it has required properties, when I use it in a read only scenario, the form comes back invalid. How can I stop the validation from occurring on the Required members in my model which aren't used on my form or supposed to be read only?
If the form is for editing the record that has been searched, then I'd suspect that your model annotations apply.
If the form is not for editing, then it shouldn't be a form. Just a collection of fields (that can still be bound to the model). In this way the automated validations managed by the EditForm will not happen.
Or, if as you've discovered you're not using all of the properties of the model, then you should consider creating a view model (not an edit model) specific for the display of data in this view panel.

MVC PartialView page rendering dropdown value and checkboxes

I am working on an mvc page, it has 2 partial views and one controller action. In one of the partial views i have a button, this button checks if the user entry exists in the database. in the other partial view i have a drop down and a table, the table is populated based on the dropdown selection.
My issue is, everytime I select some values in the table( all are check boxes) then enter some values for "Verify" button the form refreshes and clears out all selected checkboxes. is there a way to fix this?
P.S.:
I am using Viewbag to bind to dropdown selection and onchange event for dropdown.
Please guide me in fixing this. this is driving me insane.
Thank you.
If I undestand you as correctly, You can use javascript I think :). Also If you dont want to load all page, you can look ajax post with partial View in MVC
This may help your problem :D

How to bind data in controls and edit accordinly on dropdwonlist selectedindexchagned event in mvc4 razor using jquery?

I have a view for create/ edit data, in my view contains a dropdownlist control and two textboxes and two buttons [Create, Done Modifications], and my requirement is like below.
User should be able to select his/her name from dropdownlist which contains list user names. By default create button is visible and ‘Done Modifications’ button should be invisible.
Based on the dropdownlist item selection, if the record is already exists then show up his/ her data in DOB, Location textboxes then invisible Create button and able to update to the database by Done Modifications button.
Data population, edit, create, delete logic should be implement in Controller classes.
Above things should be happen in asynchronously, I don’t want to allow post backs on any events.
Thanks for your time!
Sridhar Goshika
What is the hourly rate you are going to pay for this?
This is a list of specifications given to you, that you pass on to us; It does not show any research, any code showing what you have done and where you are at. Moreover, there is no question there.
submit() method will submit the form by dropdownlist item selection
#Html.DropDownList("ProdID", null, new {#onchange="submit()" })

Insert/Remove item in listbox bound to database

I want to be able to reorder my listbox which is bound to my sql ce database by clicking up and down arrow buttons. Since my listbox is populated directly from my database using the entity framework, I think I have to delete the object (from the listbox) and reinsert it (in the row above) if I want to move the item up the list.
I have no view model, my listbox is populated directly from my database in my code like this:
listBoxProperties.ItemsSource = entities.Properties.ToList();
Does my question make sense?
Cheers
ormally you would handle the moving of your list item in your view model which would hold the ObservableCollection the control was bound to - and then that would be reflected in your control via the binding.
It is going to get messy trying to accomplish this dirrectly on the control - which is your only way since your binding to a throwaway copy of the EF properties list.
As your UI dev goes on you are only going to run into more issues like this. I strongly recommend getting a view model in place sooner rather that later.

Silverlight 4 datagrid printing

I have a Silverlight 4 app with RIA services. It's based on Tim Heuer's video and I have pretty much the same setup.
I have a DomainDataSource, a set of DomainDataSource.FilterDescriptors, a Datagrid which display 15 items per page with the help of a DataPager. When the user enters their filtering options, the datagrid updates accordingly but is still multiple pages which is okay for viewing on screen. I want to implement a print function that essentially prints the datagrid but all items at once and on multiple pages, if need be.
I have played around with printing basics and I can print the datagrid as it is exactly displayed on screen but I want to be able to print all items.
I'm not finding any good examples on the web. Can anyone suggest an approach to tackle this?
Thanks
Edit:
Not sure how helpful it's going to be but here's the XAML outline.
So one problem will be that when the user says they want to print, you'll presumably then want to ensure all the data is on the client (by executing some larger query), but let's assume you've taken care of that and have all the data on the clien and just want to focus on printing now.
In that case, I'd point you to David Poll's excellent additional printing helpers ( blog post here : http://www.davidpoll.com/2010/04/16/making-printing-easier-in-silverlight-4/ ). He provides a library (with full source) that basically takes an ItemsControl (or lots of other things, but ItemsControl is particularly relevant here) and paginates it automatically.
So you'd create a separate UserControl that has a "print view" of your data, which contains a DataGrid not limited to 15 items, removes paging UI, and basically gets everything "print-ready" (sort of like a print CSS sheet if you're familiar with that concept). Just point his library at that print view of your data, with all the data already on the client, and you should be just about all set.