2
I own a view like "List<SimpleUser>"
and I want to pass by parameter to my controller the object that is in my foreach, but this arriving null being done as follows:
View:
@{
ViewBag.Title = "Dashboard";
}
<!-- search form -->
<form action="#" method="get" class="sidebar-form">
<div class="input-group">
<input type="text" name="q" class="form-control" placeholder="Buscar entre seus clientes/pacientes..." />
<span class="input-group-btn">
<button type='submit' name='seach' id='search-btn' class="btn btn-flat"><i class="fa fa-search"></i></button>
</span>
</div>
</form>
@if (Model.Count() > 0)
{
foreach (var sUser in Model)
{
<div>
@Html.ActionLink(@sUser.Name, "ClientDetails", "ProfessionalUserHasClient", new { simpleUser = sUser })
</div>
}
}
else
{
<label>Você não tem clientes/pacientes vinculados.</label>
}
Controller:
public ActionResult ClientDetails(SimpleUser simpleUser)
{
SimpleUser sUser = ViewBag.SimpleUser as SimpleUser;
return View();
}
Change to @Html.Action()
, it passes perfectly but is carried inside the View
, an entire part of the layout, which obviously should not be loaded, follows a print of how it would look:
Using Actionlink Id is passing as null. But like A partial View I couldn’t make it work. Can you explain more the partial code? If it works already this great without appearing half the layout again hehe
– Luiz Negrini
I need it to be a link, to this clientdetails.
– Luiz Negrini
@Luiznegrini I made for you as I should be put in Actionlink a
new {Id = sUser.Id}
and put in ActionClientDetails(int? Id)
, has already been passed this so that you fit your item and work like a link as you had already reported!– user6026
your code didn’t work because it lacked a parameter in it.
– Luiz Negrini
@Luiznegrini you are very deceived, look there in the code and practically equals the answer you gave as correct!!! Believe it or not the answer is the same! but, all right!
– user6026
null parameter is missing after routevalues
– Luiz Negrini