开发者

Anchor as a Submit button

开发者 https://www.devze.com 2022-12-28 05:38 出处:网络
I have an MVC 2 application that has the following on it; <% using( Html.BeginForm(\"Results\",\"Quote\", FormMethod.开发者_JS百科Post, new { name=\"Results\" })){ %>

I have an MVC 2 application that has the following on it;

    <% using( Html.BeginForm("Results","Quote", FormMethod.开发者_JS百科Post, new { name="Results" })){ %>
        <% Html.RenderPartial("Needs", Model.needs); %>
        <div class="But green" style="">
            <a href="." onclick="javascript:document.Results.submit();">Go</a>
        </div>
        <input type="submit" />
    <%} %>

Pressing the Submit button or the anchor both post back to the right ActionResult.

However, when in the controller I return View(stuff..) only the Submit button will come back to the page.

When the call finishes from pressing the anchor, I go to an error page informing me that the resource cannot be found.

I suspect it has something to do with href="." but am unsure what to set it to.


You could try and just use a # in the href - empty in-page link I guess you could call it.

<div class="But green" style="">
    <a href="#" onclick="javascript:document.Results.submit();">Go</a>
</div>

That way it should work on any page without worrying about specifically setting the href to the view you're trying to return.


I have it.

        <div class="But green" style="">
            <a href="Results" onclick="javascript:document.Results.submit();">Go</a>
        </div>

href needs to be set to the view i'm trying to return.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号