C
C#2y ago
4

✅ Im trying to send Id from view to controller but didn't work

.
35 Replies
4
4OP2y ago
[HttpGet]
public async Task<IActionResult> Index(string userId)
{
var order = await _appDbContext.Vworeders.FindAsync(userId);



return View(order);
}
[HttpGet]
public async Task<IActionResult> Index(string userId)
{
var order = await _appDbContext.Vworeders.FindAsync(userId);



return View(order);
}
<div class="dropdown-divider"></div>
<a class="dropdown-item" method="post" asp-controller="SiteOrder" asp-action="Index" asp-route-Id="@user.Id">
<i class="fa-regular fa-basket-shopping fa-sm fa-fw mr-2 text-gray-400"></i>
My Orders
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" method="post" asp-controller="SiteOrder" asp-action="Index" asp-route-Id="@user.Id">
<i class="fa-regular fa-basket-shopping fa-sm fa-fw mr-2 text-gray-400"></i>
My Orders
</a>
what can be caused this ? @🌈 Thinker 🌈 can u help me for this ?
Thinker
Thinker2y ago
never used cshtml or mvc, sorry
4
4OP2y ago
pls some body help me
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
4
4OP2y ago
yes this is a form
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
4
4OP2y ago
one minute I'll back
4
4OP2y ago
I make it form now this button doesn't work
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
4
4OP2y ago
<div class="dropdown-divider"></div>
<form class="dropdown-item" method="post" asp-controller="SiteOrder" asp-action="Index" asp-route-Id="@user.Id">
<i class="fa-regular fa-basket-shopping fa-sm fa-fw mr-2 text-gray-400"></i>
My Orders
</form>
<div class="dropdown-divider"></div>
<form class="dropdown-item" method="post" asp-controller="SiteOrder" asp-action="Index" asp-route-Id="@user.Id">
<i class="fa-regular fa-basket-shopping fa-sm fa-fw mr-2 text-gray-400"></i>
My Orders
</form>
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
4
4OP2y ago
<a class="dropdown-item" asp-controller="Account" asp-action="Profile" asp-route-id="@user.Id">
<i class="fas fa-user fa-sm fa-fw mr-2 text-gray-400"></i>
Profile
</a>
<a class="dropdown-item" asp-controller="Account" asp-action="Profile" asp-route-id="@user.Id">
<i class="fas fa-user fa-sm fa-fw mr-2 text-gray-400"></i>
Profile
</a>
this part working but the same thing does not work in the other
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
4
4OP2y ago
[HttpGet]
public async Task<IActionResult> Profile(string id)
{
var user = await _userManager.FindByIdAsync(id);

var model = new ProfileViewModel
{
Id = user.Id,
FirstName = user.FirstName,
LastName = user.LastName,
Email = user.Email,
UserName = user.UserName,
ImagePath = user.ImagePath
};

var roles = await _userManager.GetRolesAsync(user);

if (roles.Any())
model.Role = roles[0];

return View(model);
}
[HttpGet]
public async Task<IActionResult> Profile(string id)
{
var user = await _userManager.FindByIdAsync(id);

var model = new ProfileViewModel
{
Id = user.Id,
FirstName = user.FirstName,
LastName = user.LastName,
Email = user.Email,
UserName = user.UserName,
ImagePath = user.ImagePath
};

var roles = await _userManager.GetRolesAsync(user);

if (roles.Any())
model.Role = roles[0];

return View(model);
}
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
4
4OP2y ago
should i just write id instead of userId
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
4
4OP2y ago
damn it is worked im crying
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
4
4OP2y ago
thank u vey much why ?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
4
4OP2y ago
I just learned that the word in the controller and in the view must be the same
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
4
4OP2y ago
I think I'll learn coding thank you again
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX2y ago
Collections of application ideas that anyone can solve in any programming language to improve coding skills: https://github.com/dotnet/dotnet-console-games https://github.com/karan/Projects https://github.com/florinpop17/app-ideas
4
4OP2y ago
thats my first mvc project I have console and winform projects too
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server