I am developing an ASP.NET MVC application. A user model has 4 properties:
First name
last name
Dob
Arabic name
And there are 4 members who will login. Depending on the login member I need to design the view with this 4 columns.
For example if member 1, I only want to show first name and last name.
If member 2, I need to show first name, last name and dob.
I achieved it by creating 4 different views and calling the views according to the member login. I don't think its good way of programming.
Can we store the detail in a sql table and call in view according to the member login?
For example a table with member login id and specify which are the column needs to display for him, then in view read this table and display the model values. Is this possible?
This is a role based job, so once you have created your roles for your different members you can simply add
[ReadOnlyAuthorize("A specific role")]
attribute above your field declaration
Related
I have one model 1 with Name, Surname and IDAdress (this is foreign key to other model where I have Name of street, number...).
I create a controller and views (index, create, edit...) for for model 1 and model 2 (address). Then I go in create view for model 1 where user types Name, Surname and then it has link or button on create view for model 2.
My problem is when I type in data for Adresse and redirect after post in model 2 to view create of model 1 I lose Name and Surname that user already typed in.
I hope you understand what I want to ask. Do you have any idea how to solve this?
Maybe this picture can help
Maybe this will help to understand. As you see I am leaving Create View 1 temporary so I can add info about address and after create in view create 2 I am going back to create view number 1. But if user typed in Name and Surname before adding address it has to type in that info again because I don't know how to hold that data temporary while I am adding address in view number 2.
Is there maybe a way where Create view 2 opens over create view 1 so it does not even close or I need to store type in data in some new table in database and then call those info when I am returning to view number 1...
If I understood you right you can merge your models in one big view model. Also you need to add hidden inputs to view for fields you want to pass.
How do I store different sets of user information using Simple Memberships? For eg. I have two roles (doctors and patients) respectively. The extended user information to be stored for both the roles is somewhat different. Simple Membership creates a UserProfile table by default which I'd like to split into two tables to accomodate the user information for both the roles respectively.
Please suggest if and how this can be achieved.
Thanks.
You have Roles defined in your 'Roles' Table. Then, for a particular User, UserId and RoleId both are associated with each other in another Table named '_UserInRoles'. Now, Create another table maybe Named as 'UserAdditionalInfo' and
make table structure as below
Id(PK)
UserId(FK)
RoleId(FK)
Column1
Column2
Now, you can save user additional data according to its RoleId and UserId in another table and when you need to display User Profile on front end, then may be you can use JOIN in these tables and return information.
Actually i am new learner for MVC4, my boss want to change the old asp.net webform to MVC4.
that i have some problems.
one is for each view is that need to create seperate model?
for example, in login page, users just put their name and password and submit.
so in order to receive those name and password, need i create one model for that name and password, namely one auth class with two class member, name and pass.
Or is there any better way to transfer old one to MVC
What you're talking about is a View Model - a class that represents your view / form. Instance of this class will be passed as a parameter to your Login action and will contain username and password. You will usually name your view model class after the view, eg. LoginViewModel.
It is an accepted way to create MVC applications.
I have a table per type structure, I want to write an mvc razor application where my only parameter in the mvc routing is the primary key ID. From there the application will establish which type in my tpt structure the ID belongs to then displays the view formatted for particular type.
In addition, based on the type of the ID the view will also contain information related to that ID in from other tables in the tpt structure.
E.g.
Bob is a person with ID 1234
Entity 1234 has comments in the comments table
Entity 1234 has an entry in the entity relationship table to Simon
I've read a number of articles about making a base class controller, but would my URL change from www.something.burp/1234?
Is it possible to have a set of Index, Edit, Create, Details views that have byType separation?
Just looking for some pointers or ideas for me to research.
Thanks for you help.
MVC4, EF4, C#, SQL 2008
Decided to do multi controller, it's not going to matter to the user if it goes between controllers.
i have this code in my membership service class (taken from the asp.net-mvc sample app)
public MembershipUserCollection GetUnapprovedUsers()
{
MembershipUserCollection users = Membership.GetAllUsers();
MembershipUserCollection unapprovedUsers = new MembershipUserCollection();
foreach (MembershipUser u in users)
{
if (!u.IsApproved)
{
unapprovedUsers.Add(u);
}
}
return unapprovedUsers;
}
i now need a view to show this list of information and allow someone to approve them which will go back to the controller and set the IsApproved property to true.
Create a view which will generate a form containing label and checkbox for each member of the collection. You need to be able to get from the id of the checkbox to the user.
In the HTTP.POST Action method, iterate through the submitted fields looking for set checkboxes, when you find one set the corresponding user to approved.
Obviously the form can display arbitrary details for each user.
To use the inbuilt control helpers takes a bit more effort because you don't have a fixed size model to work with. To achieve something similar I:
Used a non-strongly typed view
populated ViewData["ids"] with IEnumerable<IdType> (which the view would loop over)
For each entry populated ViewData["field" + id] for each field I was displaying in the entity
In the view looped over the ids using ViewData["ids"] to call the HTML helpers with the id of the field.
(That was V1, in V2 I used model state so I could use the inbuilt validation error display support, but that doesn't really apply if you just want to select users.)
The POST processing was similar, repopulating the id list from the database and the looking up in the passed FormCollection.