Sharing view presentation mode? - c#

I am building an ASP .NET MVC 3 application, and I want to make sure that I am following the MVC guidelines as well as possible.
I have a front page that displays a list of computer games. Now, it has the same way of displaying the items as another page. How would I do this through an MVC perspective?
Would I have a function in my controller that returns a string containing the HTML of the list of games, and then print that out on both pages? Or how would I do this in a proper way?

partial views. you should be able to find a lot of information about them via search.

Related

Transferring an existing C# and ASP.NET Web Form site to Bootstrap

So I have an existing page that's running ASP.NET and C# in order to display a front-end for some PowerShell commands. This was all developed in the community/free version of Visual Studio 2017.
Pseudo-code is below
User browses to page in browser
Browser presents lists of buttons and text fields
User inputs options into fields and clicks a button
C# runs in backend to run a PowerShell command doing various things, dumping into a JSON file the results
C# returns the results to the page by reading the JSON and turning it into a C# object, displaying as a C# Table
What I have already is that page (and sub pages for different features), displaying results to a simple table or div and displaying the buttons and text fields using the default C# table and some custom HTML to display the JSON properly.
What I want though, is to be able to port those features and functions to a Boostrap template, so I can take advantage of the handy dropdown menus, fancy buttons, etc. that are provided by Boostrap. Specifically I'm looking at using Flatkit.
All of the examples I've seen have either been for MVC stuff, starts entirely from scratch, or uses very simplistic Hello World examples, neither of which help when tackling this task as my code is web form based and more complex than an About page.
So my question(s) is/are
a) How can I create ASP.NET controls that will both play nicely with Bootstrap and feed data back into the C# file for processing? Something that can duplicate an <asp:Button> essentially, without refreshing the page entirely.
b) How can I then create another control or similar element on the front-end side to display that information? I'm using a simple <asp:Table> currently
I have the backend PowerShell and most of the logic written, I just need to know how I can make it interact nicely with Bootstrap essentially.
Web dev is not my usual forte , so a lot of the tutorials feel like reading Ancient Greek as they assume I know JQuery, Angular, DOM, etc. So if there's knowledge I'm lacking to make this work, links would be great.
Thanks!
End of day, Bootstrap or any CSS framework applies styles to HTML elements. ASP.Net Web Forms Controls render "vanilla" HTML - though some can be unwieldy (like <form> input name and id attributes - re: ASP.net uses the same value).
They can be styled as needed. Look into CssClass
Hth.

Are MVC Partial views like WebForms Controls?

Ok, the question title doesn't really reflect the question that well. But here it is in all it's glory.
I am currently making the transition from WebFroms to MVC as everyone seems to want it without really knowing why. Office politics aside.
Am I right in perceiving that a partial view is "like" a webform control in that it is an almost self-contained unit that adds to the overall _layout? IF not - could you please tell me the point and rationale of Partial views - where to use them, when and why?
Sorry not the best explanation - but it is kind of confusing for me, so it's not suprising that my question is confused as well :P
Thanks in advance.
In the web forms philosophy controls are hold UI part and some backend logic, so you can create a combobox control which always display the list items from some DB table with special stile for e.g. always in red rectangle with blue background
In the MVC philosophy partial views just an a view part, so according to the example above particular view will hold only UI component, the rest of the logic (data provider) should be in the controler's action.
MVC decouple UI from data providers, so you can create other view which still can work with previous defined data provider (action) and vice versa you can use the same partial view (view) for other data providers (actions) which have some interface
In a typical win form, you have a form that contains a few custom controls, each custom control implements part of a whole business logic, when the custom control wants to talk to each other, they will pass data across via presenter. Also, each custom control is a combination of windows standard controls(button, label, textbox,etc). In such case, you can think that each standard control is a html element, custom control is partial view, the whole form is a view and presenter is action method + ajax call.
MVC and WebForms are both programming models.
Comparing partial views to Webforms is not comparing apple to apple.
You have to think different when it comes to MVC or even forget about the WebForms
The closest thing to a partial view in webforms would be master pages in my opinion. And that is just the aspx markup aspect (View) of it.

Using ASP.Net Web Databound Controls to create Jquery Sliders tickers type controls

I am working on a B2B portal web app, where i need to display upcoming news , products and company info on regular interval (say as slideshows and tickers).
For example :
Scenario 1. I need to display the latest company(registered in this week) in a marquee style. Where companies will be pulled out from database.
Scenario 2: I have some products categorized as hot products, that will be displayed as slideshow on the home or somewhere else.
I know using Jquery and Static pages its possible. But i havent idea about how to do this with ASP.Net databaound controls like grid, repeaters, datalist etc. We are not in favour of purchasing third party controls, instead it will be a last resort for us.
Please help me through buil-in controls. Any help will be highly appreciated.
You should decide whether you want to do with JQuery Widgets or ASP.NET controls (or third party ASP.NET controls like Telerik). Can you use both - yes you can, but you are only going to add more complexity to your app because ASP.NET controls don't know about your JQuery Widgets and you have to provide the glue to tied them both and keep them synched up. So if you decide to build everything in JQuery - convert your static html pages to .aspx pages then add additional serverside functionality to return the data. For AJAX behavior, you can use what is called Page Methods in ASP.NET or write seperate Script Services. You will make use of what is called a ScriptManager. That way you can keep your existing markup and rely on ASP.NET to provide you with Data. The other alternative is to convert everything to ASP.NET Controls - and rely on the builtin or third-party control suite to provide the functionality.

New MVC2 Application Suggestion

I'm starting a project in ASP.NET MVC2 where I have a need to let the user select item(s) from a table with about 40000 records. This is NOT a shopping cart application.
I'd like to accomplish this using JQuery popup. Here is the order I have in mind...
Please think of this as building a new car
Customer starts to build a new car
Enters some basic info such as name, # of cylinders etc
Clicks an icon to show a JQuery modal popup to search parts required
Selects an item/part after the search returns
Selected item shows up on the underlying [parent] page.
Repeat steps 3, 4, 5 to select additional items/parts.
Then Save to database in a Master/Detail type tables
This is similar to a shopping cart except there is no checkout and the user enters the order info before making the selections and I noticed that JQuery interfaces seem to appear richer.
If this is doable, I'm looking for suggestions and/or examples or a path to follow, being new to both MVC and JQuery.
Example of what I want to achieve can be seen at www.pageonce.com, only in a much smaller scale.
TIA
ASP.NET MVC2, MS SQL Server, JQuery
Start with understanding how you will achieve Ajax with Asp.net MVC. Another suggestion is that consider moving to Asp.Net MVC 3. You will get Razor view engine and lots of Web Helpers which can enhance your UI further.

ASP.NET MVC and ModalPopupExtender

I am developing an application with ASP.NET MVC and wish to make use of Modal style windows.
Here is one example. On my "Login" view, I have my login details, but also have a button to create an Account for the application. I have a separate "CreateAccount" view, but would like it to pop up inside a ModalPopupWindow.
Is this possible usng just ASP MVC and the ASP.NET Ajax Library, or will I have to use a different Ajax library?
(Another way to ask this question: can I redirect the output of a view into a ModalPopupExtender?)
Jason
I would suggest you returning a PartialView from your controller and loading the result in some jQuery plugin to show popups in the same page context like this
The usage is something like
Boxy.load('/Account/Create'); // You can post additional data if you need to
This way you will have a beautiful Box (facebook like) with your form in it. You just have to be aware that if you post something in it, you should do it using AJAX to update the response in the same Box.
Good Luck!!

Categories