0

In my controller I have some code, and final part which is returning all results to my view is:

public ActionResult Index(SearchParameters parameters)
{
... some code ...
var view = new SpremenljivkeView
{
    Spremenljivke = matchingSpremenljivke,
    Search = parameters,
    TotalCount = matchingSpremenljivke.NumFound,
};

return View("../Login/Index", view);
}

Now I whant to send results in View if string in parameters (Internal number) are not empty or null. If is null, return empty value, if not return view with results.

I have try this:

...
if (!string.IsNullOrEmpty(parameters.Internal))
{
  var view = new SpremenljivkeView
  {
    Spremenljivke = matchingSpremenljivke,
    Search = parameters,
    TotalCount = matchingSpremenljivke.NumFound,
  };

  return View("../Login/Index", view);
}

But return View cannot be inside If sentece. Any idea how to correct this...

Thanks for any ideas.

1 Answer 1

2

you need to return EmptyResult in else part as Action nneds to return ActionResult:

if (!string.IsNullOrEmpty(parameters.Internal))
{
  var view = new SpremenljivkeView
  {
    Spremenljivke = matchingSpremenljivke,
    Search = parameters,
    TotalCount = matchingSpremenljivke.NumFound,
  };

  return View("../Login/Index", view);
}
else
{
return new EmptyResult();
}

and if you want to return same view without values then return only view in else part:

return View("../Login/Index");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.