37 मुझे एक समस्या आ रही है जहां मैं अपना ASP.NET MVC एप्लिकेशन खोलने का प्रयास करता हूं लेकिन मुझे ASP.NET त्रुटि पृष्ठ मिलता है जो यह कहता है:


Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Home/Read

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.9220.0

मैंने क्या प्रयास किया है:

अनुक्रमणिका

एएसपी
@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<html>
<head>
    <title> ViewBag</title>
</head>
<body>
    @using (Html.BeginForm("Read", "Home", FormMethod.Get))
    {
        <fieldset>
            <legend> ViewBag</legend>
            <table>
                <tr>
                    <td>
                        @Html.Label("Enter Id Here :")
                    </td>
                    <td>
                        @Html.TextBox("ID")
                    </td>
                </tr>
                <tr>
                    <td>
                        @Html.Label("Name :")
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td>
                        @Html.Label("Age :")
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="submit" value="GetRecords" />
                    </td>
                </tr>
            </table>
        </fieldset>
    }
</body>


</html>

कंटोलर

सी#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace NewView.Controllers
{
    public class ViewBagViewController : Controller
    {
        Dreal1Entities1 db = new Dreal1Entities1();
        
        //
        // GET: /ViewBagView/
        public ActionResult Index()
        {
            return View();
        }

        public  ActionResult Read(int ID)
        {
            var Name = db.tbl_add.Where(p => p.Id == ID).FirstOrDefault().Name;
            var Age = db.tbl_add.Where(p => p.Id == ID).FirstOrDefault().Age;
            return View("Index");
            
        }

	}
}

समाधान 1

डिफ़ॉल्ट मार्ग है /[Controller]/[Action]. इसलिए, के लिए /Home/Readआपके पास एक कार्रवाई बुलाई जाएगी Read एक नियंत्रक पर कहा जाता है HomeController.

आपके नियंत्रक को बुलाया जाता है ViewBagViewController. इसलिए, आपका यूआरएल होना चाहिए /ViewBagView/Read के बजाय /Home/Read.

コメント

タイトルとURLをコピーしました