Click here to Skip to main content
15,880,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wanna add master page to my mvc application but its not layout i need to write materpage.cs code so were to add it and how i select this when im adding a view.

Or i need to use filters in mvc. If so how can i use this .Im beginner for mvc

Or how to pass data to a layout
Posted
Updated 11-Dec-13 18:22pm
v3

The concept of Model View Controller does not support code behind file. So, if you want to write masterpage.cs that is not directly possible or should not be.

If you want to filter in then you have to mention clearly, what type of filter you want to use. there are few types of filtering like action filter and others.

Then your last question, if you want to change a value of _layout's control. Then make it as a partial view. For a specific reason or in an action if you want to change the value of layout control then call the partial view again.
 
Share this answer
 
Comments
Usha Sanjee 13-Dec-13 23:56pm    
welcome user username changepassword
home aboutus contactus
content

Footer



here i need to maintain the username at top rightside how could i do this.
I tried to pass the data of username in index control but it visible only in index view not in others i hope its because im tried to getting the data from index control not from other action controls.

I lisened about filters concept these are useful to write the logics before or after the actions so i thought it may use. But i dnt knw which type of filters to use or how to use that to my requirment. (I'm using MVC4)
for this scenario, filtering will be more expensive. So use a partial view. For example, the partial view name is "LoggedInInfo.cshtml".

_Layout page you have to call this view using an action, like @Html.Action("loggedInAction","Account") every time. Inside this action you have to check that your form is authenticated or not. if yes then pass the user name to the partial view using viewbag or viewdata. Ohterwise do nothing.

It should be noted here, you have to keep the Idenetity of user in Current Context which is accessible from any where your application.

So, My suggestion is to use Form authentication and keep the user idenetity in current context and make the logged in info as a partial view.
 
Share this answer
 
Comments
Usha Sanjee 17-Dec-13 0:38am    
Im trying partial view but when i use 2 models in one view i getting error then i foolowed this
http://stackoverflow.com/questions/5550627/two-models-in-one-view-in-asp-mvc-3
But again im getting this error
'MVC4.Models.MainPageModel' does not contain a definition for 'FirstName' and no extension method 'FirstName' accepting a first argument

Here the model is not able to recogonize i hope how could i solve this issue
[no name] 17-Dec-13 2:18am    
Use a composite class, i mean another class which will be initialized your two model and then pass it to view. One thing for data binding expression. You have to maintain its hierarchy.
eg: if you pass an object A, this A object will have more two object a and b. The object have firstname and lastname. Then you have to bind A.a.FirsName.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900