0

FRONTEND

@{
    <div>
        @Html.RenderAction("UrunOzellikTipWidget", "Admin");
        @Html.RenderAction("UrunOzellikDegerWidget", "Admin");
    </div>
}

BACKEND

public ActionResult UrunOzellikEkle()
{
    return View(Context.Baglanti.Urun.ToList());
}

public PartialViewResult UrunOzellikTipWidged(int? katID)
{
    if (katID != null)
    {
        var data = Context.Baglanti.OzellikTip
            .Where(x => x.KategoriID == katID)
            .ToList();
        return PartialView(data);
    }
    else
    {
        var data = Context.Baglanti.OzellikTip.ToList();
        return PartialView(data);
    }
}

public PartialViewResult UrunOzellikDegerWidget(int? tipID)
{
    if (tipID != null)
    {
        var data = Context.Baglanti.OzellikDeger
            .Where(x => x.OzellikTipID == tipID)
            .ToList();
        return PartialView(data);
    }
    else
    {
        var data = Context.Baglanti.OzellikDeger
            .ToList();
        return PartialView(data);
    }
}

**ERROR CODE:Severity Code Description Project File Line Suppression State Error CS0029 Cannot implicitly convert type 'void' to 'object' **

David Liang
  • 20,385
  • 6
  • 44
  • 70
  • From the limited info provided, is `KategoriID` and `OzellikTipID` nullable int? If not then try to change `== katID` into `== katID.Value` and `== tipID` into `== tipID.Value`. You may also take a look at this: https://stackoverflow.com/q/8959425/13742790 – Bemn Jul 11 '20 at 13:50
  • The problem has nothing to do with the back door, no matter what action name I give at the front, it gives an error. – Muhammed Şeker Jul 11 '20 at 14:03
  • You have redunant `@` characters in the code block shown for the 'frontend'. Remove the `@` characters from both `@Html.RenderAction(` statements because the ampersands are not needed -- those lines are already inside an ampersand block like this `@{ ... }` – David Tansey Jul 11 '20 at 19:53

2 Answers2

0

Revise your code in FRONTEND to the following (remove the redundant ampersands from both Html.RenderAction statements).

<div>
      @{ Html.RenderAction("UrunOzellikTipWidget", "Admin"); }
      @{ Html.RenderAction("UrunOzellikDegerWidget", "Admin") };
</div>
David Tansey
  • 5,813
  • 4
  • 35
  • 51
0

@Html.RenderAction renders the result and, instead of returns it as string, writes it directly to the response and returns Void. So you will have to use it inside a C# block, denoted as @{ }, and end it with a semicolon at the end, just like how you invoke/call a void function.

So your front-end needs to be changed to:

<div>
    @{
        Html.RenderAction("UrunOzellikTipWidget", "Admin");
        Html.RenderAction("UrunOzellikDegerWidget", "Admin");
    }
</div>

The other's answer (removing the redundant ampersands) won't work because those 2 RenderAction are wrapped inside a <div />. If you remove the ampersand, they're treated as just regular HTML. It will output as:

enter image description here

David Liang
  • 20,385
  • 6
  • 44
  • 70