Problem with Html.Partial and Viewbag

Asked

Viewed 64 times

2

I have my following controller:

public ActionResult Index2(int Id= 0)
{
  if (Id == 0)
  {
    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  }
  ViewBag.ClienteId = Id;
  return View();
}
public ActionResult Index3(int Id= 0)
{
  if (Id == 0)
  {
    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
  }
  ViewBag.ClienteId = Id;
  return View();
}

and others

In all of them, I have a partial with the following code:

        @Html.Partial("_MenuInfo")

And in it I have my menu with the Customer ID, as I go through the Viewbags

<div class="col-md-12">
    <div class="row">
        <ul class="nav nav-tabs" role="tablist">
            <li class="active"><a href='@Url.Action("Novo", "Grupo", new { area = "Cadastro" })/@ViewBag.ClienteId' class="btn btn-success">Grupo</a></li>
            <li><a href='@Url.Action("Novo", "Acesso", new { area = "Cadastro" })/@ViewBag.ClienteId' class="btn btn-success">Acesso</a></li>
        </ul>
    </div>
</div>

But as I navigate the links

It is rendering the following link

Group/New/17/17

That is, it is generating twice the code of the Customer that comes from Viewbag

I need this menu to be in several Views, so when I go to give a "New" I already send the Customer Id that is a FK in the table

1 answer

2


Utilize:
@Url.Action("Novo", "Acesso", new { area = "cadastro", id = ViewBag.ClienteId })

Instead of:
@Url.Action("Novo", "Grupo", new { area = "Cadastro" })/@ViewBag.ClienteId

Browser other questions tagged

You are not signed in. Login or sign up in order to post.