Is this the right MVC Application Structure - asp.net-mvc

Requirements:
1.A page showing list of id's from the database.
2.Once the user clicked the item ID in the list, a modal will pop up showing all details from that id
Problem:
MVC seems to required another URL in order to use the selected id that cause redirection from another page showing the id details
Solution:
so what i did is put the list into a partial view and call the partialview in another page pretending that it didn't redirects.
Question:
Am I doing it the right way or a dirty way?
Do MVC behave this way?
If you have any suggestions please let me know.

this is not the mvc issue, if you want to popup a modal window to show the detail information, there are many ways can do that, this is the javascript issue, you can use jquery dialog or sweet alert2 or others js lib for that.

Related

Rails - manipulating data in popup

I'm new in Rails, I have a Meal model which has many Products. Meals are assign to User (maybe this is important for a concept). In meals/new.html.erb I want to create new Meal as follow:
Click the button "Display Products"
On the same page (meals/new.html.erb) open modal (pop-up) with all products assigned to current user ( I have help method for current-user). It should be displayad like a list or grid with checboxes for example.
Then user can check few products and click "Confirm".
After that in meals/new.html should be appeared list of chosen products with additional input to fill their quantity.
So I have two problem here.
How should I display modal? Is needed any Ajax (I'm not so familiar with this technology)
How can I pass products between view and modal?
Could you help me a little to achieve these goals?
Regarding your first problem, displaying the modal is fairly straight forward. Essentially you will create a div with the proper bootstrap classes to be hidden when the page is loaded, and then create a button that makes it visible. I would recommend either reading over the W3Schools entry on modals, or from the appropriate part of the bootstrap javascript documentation.
Regarding your second question, this depends on exactly what you mean. The modal is part of the view, so if you're only trying to put information that is currently on the modal back onto the "page" behind it, you can do so fairly simply with javascript (copying content out of one element into another, or updating states of inputs). If, on the other hand, you're trying to use the modal to retrieve information from the server (for instance if you wanted to show a list of possible options, and then display detailed information about the selected items from the database) that would require Ajax.
If you have any snippets of code that aren't functioning as you expect, feel free to add your View to the question. In cases like this, usually the best way for us to provide help is for you to take an early crack at this, post the relevant code, and then seek answers for the things that behave unexpectedly.
I hope that helps.

Rails Ajax Or Javascript?

I was wondering which way would be the best for my following problem. and maybe sample on how to do it also
I have the following models: customer, music, books.
What I would like to do is when a customer wants to go into the edit page then automatically customer general information such as name, password show up! But on an other tab by pressing music which his another model then music information comes up in the same. Sorta like facebook and twitter edit page do it.
Now each of the form are rendered by the following code line at the moment
<%= render 'general'%>
but how do i include them in the link and should i just use javascript and toggle them or use ajax ??
Thanks
Well, this has little to do with Ajax, since all information you need aparently would already been loaded by you main customer object.
What i understand you want is something like the tabs javascript plugin of twitter bootstrap: http://twitter.github.com/bootstrap/javascript.html#tabs
You put the different content (music/books/etc) in different divs and when the tab is clicked, the content changes and the user gets a better experience.
Take a look at the link, it is super easy to set up this plugin on your project.

ASP.NET MVC 3 Session

I am very new to MVC. I am coming from web forms.
I have a simple search page. The user has option of searching contacts by state. I have a multi select box where they can select multiple states and click search contacts.
The result contacts will be displayed in a grid. The grid has options of edit,details and delete.
When they click delete it goes to a different page and asks for confirmation. Once they click delete and its done succesfully i am redirecting to the search page. But i want to redirect them to the same list they have earlier.
How i can acheive this with MVC ??
I am storing the selected state ids in an integer array in the view model.
You could try doing a modal popup and then doing an Ajax request and bind the results to a Partial view on the page.
Ie. $('#partialDiv').load( your controller call here )
Might make for a better experience...

How to persist a model across multiple requests in ASP.NET MVC 2

I'm building a web application that has a particular model representing some events. Users need to be able to add N number of people to a given event. Choosing people is handled by a partial view.
I'm trying to build a menu that displays when users click "add a person" to the event. Because the event hasn't been filled out completely yet, there is nothing in the database to persist between requests.
I also have validation logic on the event page.
My proposed solution is to add the form to search or add for people on the event form itself and have a submit button that sends the values that have been added back to the server, where I can store them in ViewData or Session.
Unfortunately, doing this flags the validation.
My second solution is to load a partial view responsible for loading the UI to add/search for a person. I could add a little code on the method in the controller that returns a partial view storing the existing data in a session variable or viewdata. Trouble is, I have to submit the form to do it--again tripping the validation!!!
I'm wondering if perhaps I chose the wrong tool to do this...because in webforms, there would probably be a postback and you would just perform an operation on that postback. I'd like to avoid rewriting the application in webforms and am wondering if there are ways I'm overlooking in ASP.NET MVC.
Thanks in advance for the ideas!
I would probably have the partial view send it's data to the main page (with javascript). That way there is only one post to the server and it is when all of the data the user needs to enter has been filled out. How are you displaying the partial view? Is it on the main page (in a div), or is it a separate pop-up window? Either way, you should be able to use javascript to store this data on the main page and post all of the data back at one time.
HTH

Passing dynamic data to controller with ASP.NET MVC and jQuery on form submit

I have a website which is basically a single page containing a bunch of dynamic content. In normal operation the user should never leave this page. To handle/report certain errors though, I need to redirect to an error page. So on the error page I want to provide a link back to the normal page which provides the app the information required to rebuild all the dynamic content which was previously open.
I think I can rebuild the page by parsing the querystring with javascript and reloading dynamic content. I'm not sure if this is the best way, but I've got it working. So href in the link on my error page needs to look something like:
MySite/MyController/MyAction?1,5,8,9
where the numbers in the querystring basically indicate the Id's of content sections to load in on document.ready.
I'm now stuck on how to generate this link though. I think I need to pass these numbers into the controller somehow, so the controller can pass them into the error view which will then generate the "back" link.
I have a standard html form for uploading a file:
using (Html.BeginForm("MyAction", "MyController",
FormMethod.Post,
new { enctype = "multipart/form-data" }))
{ /* ... */ }
I then have a button which calls the jQuery .submit() method on the form.
So, the question, when I click on the button which submits the form, how can I attach the additional data so I can access it in my controller?
Hope that's clear, if not let me know and I can provide more detail. Thanks.
Edit: It occured to me that I could submit this information with a hidden field in the form. I'll try that if I can't find a better way, but I'd like a more generic solution if possible as I have a number of forms on the page and ideally I'd like this data available to any/all of them.
your url should be biult just before sending the form with .submit() not in Html.BeginForm tag....
i can't see the problem over here... what exactly you are dealing with?
I know this is not quite what you asked but instead of going through the hassle of redirecting the user in the first place why don't you show a modal window (a jquery based one) that contains an iFrame. The iFrame href can be determined by the calling page and can show the error page.
Not sure if this helps but I have used this technique and found that I do not need to worry about getting the user back to the place where they started from. Additional to this you will not need to rebuilding/reloading the orignal content as it will still be on the calling page.
****EDIT**** After reading your comments maybe you could do the following...
On the link click - open up a modal popup pointing to an iframe.
The iframe calls the action on the controller to download the file.
The view could say "Downloading file... please wait, click here to close etc."
If the action throws the error then redirect to the error page as normal as it is within the iframe modal popup.
This way you do not need to leave the current calling page.

Resources