I have an ASP.NET MVC app and I have a WebForm page I built in the MVC due to a tutorial on how to do something I needed to do, but it was all in WebForm style. Ive tried to figure out how to do the same thing in MVC format but cant figure it out. So I was needing to figure out how to use this page in my MVC app. But when I try to go to the page, it gives me the error "Page cannot be derived from ViewMast开发者_如何学JAVAerPage unless Page derives from ViewPage." So I had to make a new standard MasterPage also.
The situation is this. I have a search bar located in the MVC ViewMasterPage thats on every page that is derived from it. Once a user submits info in the search bar, it calls the WebForm Search.aspx page and displays the results on the Search.aspx page. I want the URL to be like "http:///search//. The Search.aspx page is located in the root of the project. How would I get the results Im looking for? Thanks!
You're probably going to want to re-implement that web form in proper MVC. The two can play nice together in the same web app if you know what you're doing, but if you're trying to implement the whole thing in MVC then just sticking with a web forms tutorial for the occasional page is probably going to make the whole thing a lot more difficult to support. (As you've already learned from having to make a second master page.)
Study the tutorials, but make it a point to learn exactly what it is they're doing rather than just copy/paste the code. The actual implementation on your end sounds like it should stay in MVC.
ASP.NET WebForms can absolutely handle the routing. I've recently built a very large site that is completely WebForms and completely routed. There is no public indication that it is an aspx site other than Viewstate and the other tell-tale form garbage.
<system.webServer>
<rewrite>
<rules>
<!-- If a user requests the search.aspx page, redirect them to /search -->
<rule name="Search-Redirect" stopProcessing="true">
<match url="^search\.aspx$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
</conditions>
<action type="Redirect" url="search" appendQueryString="true" />
</rule>
<!-- If a user requests the search page with a query appended to the URL, send them to the search.aspx page and put the training URL into the q query string -->
<rule name="Search-Query-Rewrite" stopProcessing="true">
<match url="^search/([_0-9a-z-]+)" />
<action type="Rewrite" url="search.aspx?q={R:1}" appendQueryString="false" />
</rule>
<!-- If a user requests the search page without a query appended, just send them to the search.aspx page -->
<rule name="Search-Rewrite" stopProcessing="true">
<match url="^search$" />
<action type="Rewrite" url="search.aspx" />
</rule>
</rules>
</rewrite>
</system.webServer>
You might need to tweak this a little depending up your URL structure, how you intend for the search criteria to come into the page, but it will work.
精彩评论