combine Details view and Create View - asp.net-mvc-4

Good day! I'm still in the process of familiarizing MVC 4 and I have this project in which I have a ParkingLotController which it suppose to have 1 Create view which is an application form and 1 combined Create and Details view where I can View the datas from the application form and add datas by the use of the create function.
(Edited)
Sorry I forgot mention that I haven't done it yet. what i'm asking is, is it possible to do it? how can i implement the idea? thanks!

Related

Comment functionality on every page in Yii 1.1

I am using Yii 1.1.16 for one of my projects.
I have 5 controllers at the moment, and their data is coming from their respective models.
Now I want to add new functionality into my website, regarding comments. I want to add a form at the bottom of each view, but obviously the data will be coming from another database table (I have created a new model for that).
I am confused. Should I create 5 different forms in HTML for my problem, or can I use Yii widgets functionality to implement the same?
The Comment table would be the same for every user in the database. Comments will be coming with the help of their user id, which is stored in the table, and their comment will be inserted with the help of their user id, too.
Please let me know the best solution you can think of.
I suggest to create one widget for displaying comments section and one controller for handling request from this widget (for example adding new comment or displaying different page of comments list). In this way adding comments for any section should require only few lines of code to initialize widget:
$this->widget('CommentsWidget', [
'parentId' => 'page-' . $model->id,
]);

Yii - Create items list

is there a simple way of creating a list with editable elements (add/remove) on a page?
Something simillar to the users managing list, where you can add and delete users.
For example, you got a table in DB with 2 columns - "Name" and "Value", and rows like
"Onion"-"10" and "Potato"-"20". The idea is to display the table on a page and make it editable.
Sounds simple but im new in Yii, just yesterday learned about it, did first app and other stuff from guides, but there is no guide how to create things like that manually (so far i was installing widgets mostly)
Thanks
The component you need is CGridView. Take a look to this website.
Yii Playground

Where is the equivalent of WebForms' Master Page codebehind files in ASP.NET MVC?

Today is my first day working with MVC and I am trying to convert my existing Web Forms website into an MVC 4 site.
I have done some reading and am starting to understand how things work but one thing I can not figure out is for the new Layouts (replacing MasterPages) where is the equivalent to the codebehind file? In my current site I have a Master Page that defines the general look and feel but also runs some code in the codebehind to changes a few things dynamically (for localization and DB generated menu system).
So now that I am using MVC and Layouts I can not figure out where I would code all that at, can anyone please point me in the right direction?
(I know MVC does not have code behinds it uses controllers for it.)
As you Know MVC is three layer architecture.
Model
View
Controller
Model is the data entities. You need to store, or show the data.
Views are the html or presentation layer which would be rendered to users.
Controller are the code behind file all of your code would go in controller. It gets data from Models and apply business logic and then pass to views to show or get updated data from view and pass to models and then save to database.
_layout.cshtml file is present at path of ~/Views/Shared/_Layout.cshtml. It is master-page in mvc. You would see your partial-views contains
Layout = "~/Views/Shared/_Layout.cshtml";
this line at top of page. You can change master-page for any views and you can have multiple Layouts.
Layout contains many partial-views like left-navigation, Top-Navigation and content. each of which can be customized from controller.
Here are some links might help you:
MVC Tutorials
Introduction to MVC
Create a Base Controller class and make all your controllers inherit from it.
The MVC equivalent of WebForms' Master Page codebehind is then this Base Controller, where you can put code you need for multiple controllers.
How can I execute common code for every request?
You can't find any examples of what you're trying to do, because that's not how it's done in MVC. There is no equivalent to code behinds.
You're "trying to do" the wrong thing. MVC layouts are simply template files. They have no code behind, and they should have no functionality besides simple display logic.
MVC is a different paradigm from WebForms. You don't use have server-side controls like WebForms. Therefore the idea that you have content in the layout that does it's own thing violates the MVC principles.
You're basically stuck in what's known as the XY problem. That's where you are trying to achieve certain functionality X, and you believe to do that you need to do Y, so all you ask about is Y... when X is what you really need to be asking about.
Please explain the actual thing you are trying to do, and don't assume that it must be done in the way you've always done it. For instance, if you want to localize something, then ask how to localize something. If you want dynamic content somewhere, ask how to do that, but you need to be more specific about these individual problems, and not just gloss over them as you have done here.

Yii Problems With The Testdrive Example

I'm trying to create my first Yii application, step by step, with the testdrive example but I meet some problems.
When I try to create a new user, I obtain an error CException:
UserController cannot find the requested view "_form".
If I understand you correctly, you've created a protected/controller/UserController.php.
From the sounds of it, somewhere in that code you have a call to render (or partialRender), that looks something like this:
$this->render('_form');
For this to work, you'll need a corresponding view file. Views should go in protected/views/<controllerName> and should be files that correspond to the view name you use. In your case, you'll need a protected/views/User/_form.php.

Append HTML table to another table

In my Sencha Touch 2 application I have an HTML table in a view which has its ID. What I'm trying to do is do some actions, load store, create another table and append it to the existing table - without changing the view. I have no problems with making the request, creating the second table on the fly, etc, however I need to figure out how one table can be appended to another in terms of Sencha Touch? Is there an "appendTo()" function like, say, jQuery has and how can I use it? I basically need to get the table by its ID and append the new table to it. But don't know how to do that in Sencha Touch 2. Any help is greatly appreciated.
Thank you.
It depends what your view extends but if it's extending an xtype:panel then you can use getHtml() to get the existing content and then setHtml() to update it.