0

I have 2 .cshtml files 1)Index.cshtml in Home folder of the Views 2)Create.cshtml file in Testing folder of Views

--Index.cshtml

<div id="body" align="center">
    <section class="featured">
        <div class="content-wrapper">
            <hgroup class="title">
                <h1>Testing controller!</h1>
            </hgroup>

        </div>
    </section>

        <section class="content-wrapper main-content clear-fix">

             <p>
                test View : <a href="~/Views/Testing/Create.cshtml">Click Here!</a>
            </p>     
        </section>

</div>

Now in Index.cshtml in the a href , I want to get to Create.cshtml. How can I do that? The above code give "resource not found error".

Thanks R

newbieCSharp
  • 181
  • 2
  • 22

2 Answers2

2

Make your link like

 @Html.ActionLink("Click Here!", "Create", "Testing", null, null);

Where Create is your ActionName and Testing is your ControllerName. On Controller it would look like

class TestinngController : Controller
{
    public ActionResult Create()
    {
        return view();
    }
}
Ashish Rajput
  • 1,489
  • 1
  • 11
  • 20
0

Yes, this is because cshtml is a razor engine file and not a normal html file which your browser can view, I think we will need to do an edit in your IIS settings to allow cshtml to view on browsers, but to show this file the normal way your will need to call its view action or use something like RenderAction, RenderPartial Html.Partial vs Html.RenderPartial & Html.Action vs Html.RenderAction

Community
  • 1
  • 1
Amr Elgarhy
  • 66,568
  • 69
  • 184
  • 301