Home Issue with Delete Action returning HttpNotFound MVC
Reply: 0

Issue with Delete Action returning HttpNotFound MVC

user1323
1#
user1323 Published in July 19, 2018, 7:49 am

i have list of user Emails and than i try to make delete method , but i didnt understand why it just returning HttpNotFound , did i miss something!Can anyone direct me in the right direction? thx

Controller:

public ActionResult Delete(string User) 
{

    var db = new DataContext();
    var u = db.PX.Find(User);
    if (u==null)
    {
        return HttpNotFound();
    }
    return View(u);

}
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(string User)
{
    var db = new DataContext();
    var u = db.PX.Find(User);
    db.PX.Remove(u);
    db.SaveChanges();
    return RedirectToAction("Index");
}

View - Index:

<table>
    <thead>
        <tr>
            <th>Email</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var user in Model)
        {
            <tr>
                <td>

                     <a href="/User/Delete?User=@user.Email">delete</a>
                </td>
            </tr>
        }
    </tbody>
</table>

Class :

public class user
{
    public string Email { get; set; }
    private string password = "";

    } }
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.33945 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO