I have one method in Inside of Razor view.
<div style="height: 50px; padding-left: 10%; width: 100%">
<b style="font-family: Arial, Helvetica, sans-serif; font-weight: normal; font-size: xx-large">
@functions {
public string schoolname()
{
if (Request.IsAuthenticated && !User.IsInRole("SuperAdmin"))
{
string currentUserName = User.Identity.Name;
return GetHeaderSchoolName(currentUserName);
}
return string.Empty;
}
public string GetHeaderSchoolName(string userName)
{
Guid userId = SchoolBreifcase.Utilities.Common.GetUserId(userName);
SchoolBreifcase.Repositories.AdminRepository adminRepository = new SchoolBreifcase.Repositories.AdminRepository();
SchoolBreifcase.Models.Edmx.UserProfile userProfile = adminRepository.GetUserProfileByUserId(userId);
string CurrentSchoolName = userProfile.School.SchoolName;
return CurrentSchoolName + "xxx";
}
}
</div>
I have one button in inside of same razor view.And I called that method(schoolname()
) in my below button onclick event (onclick="schoolname()"
) please see below
<div class="logoHeader" style="float: right; width: 15%; padding-top: 5%;">
**<button onclick="schoolname()"> xx</button>**
</div>
But .Its Not working . My method is does not called .I have no idea for this task . You have Any idea here? and how to do solve this ?
Updated:
I know the procedure are threw controller ,action result,get ,post, java script,jquery,etc ,all . My question is What is use of @functions
? in razor view . I know its helping to write server side code in inside of razor view . but i can't call this method in just one button click event . So what is the use it ? Its only used only for when page load .
Finished my self :
See below my Razor View Function :
<div style="height: 50px; padding-left: 10%; width: 100%">
<b style="font-family: Arial, Helvetica, sans-serif; font-weight: normal; font-size: xx-large">
@functions {
public string schoolname()
{
if (Request.IsAuthenticated && !User.IsInRole("SuperAdmin"))
{
string currentUserName = User.Identity.Name;
return GetHeaderSchoolName(currentUserName);
}
return string.Empty;
}
public string GetHeaderSchoolName(string userName)
{
Guid userId = SchoolBreifcase.Utilities.Common.GetUserId(userName);
SchoolBreifcase.Repositories.AdminRepository adminRepository = new SchoolBreifcase.Repositories.AdminRepository();
SchoolBreifcase.Models.Edmx.UserProfile userProfile = adminRepository.GetUserProfileByUserId(userId);
string CurrentSchoolName = userProfile.School.SchoolName;
return CurrentSchoolName + "xxx";
}
}
</div>
And I am used javascript:window.location.href="schoolname"
for call my function .Its working now .
<div class="logoHeader" style="float: right; width: 15%; padding-top: 5%;">
**<button onclick='javascript:window.location.href="schoolname"'> xx</button>**
</div>
Thanks Guy's .