user2978275
user2978275

Reputation: 11

Return a message when search item is not found

How I could return a pop-up message that the search item is not existing? I have code below and it will just return a the heading portion on my table....

public ActionResult Index_PRFStatus(string searchBy, int id)
{
    List<purchaseOrder> po = new List<purchaseOrder>();
    po = db.purchaseOrders.ToList();

    if (searchBy == "close")
    {
        if (id == null)
        {
            return HttpNotFound();
        }
        po = db.purchaseOrders.Where(x => x.prf_Id == id).Where(x => x.selected_supplier != null).ToList();
        return View(po);
    }
    else
    {
        return View(po.ToList());
    }
}

Upvotes: 1

Views: 327

Answers (2)

Pelle
Pelle

Reputation: 1

Are you building your project in ASP.NET? If so, you cannot simply use MessageBox.Show. A better solution would maybe be to use javascript, like someone else implied.

Here's an example:

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "success", "alert('Could not be found'); {location.href='/Your.aspx';};", true);

Upvotes: 0

itsme86
itsme86

Reputation: 19516

You can use a javascript alert() in the view if you really want a pop-up message. Or, you could just inform them on the page that there were no results:

@if (Model.Count == 0) {
    <span>No results found</span>
} else {
    // Make your table
}

Upvotes: 1

Related Questions