mvc-System.Web.Mvc.ViewUserControl

发布于 2024-10-16 01:25:03 字数 1284 浏览 0 评论 0原文

嘿... 如何在后操作中将提交按钮的 id 从 ViewUserControl 发送到控制器?当我有正常的视图时,我可以写这样的东西:

[HttpPost]
public  ActionResult KontaktIzabran(string myId)
{
    //some code 

}   

Now myId is alwasy null.... 这是我的用户控件

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<KontaktModel>" %>
<%@ OutputCache Duration="1200" VaryByParam="*" %>
<div id="sign-in-pop" class="popup">    
<div class="modal fat-form">
    <div class="clipper">
        <div class="left"></div>
        <div class="content">Sign In</div>
        <div class="right"></div>
    </div>                    
    <% Html.BeginForm("IzborKontaktaPopUp", "Kontakt"); %>
         <%: Html.ValidationSummary(true) %>
        <div class="editor-field">
            <%: Html.TextBoxFor(model => model.Naziv)%>
            <%: Html.ValidationMessageFor(model => model.Naziv) %>  
            <input type="submit" value="Traži" name="submitButton" id="submitButton" />
            <input type="submit" value="Dodaj novi" name="noviKontakt" />
        </div>
    <% Html.EndForm(); %>
</div>       
</div>   

Hey...
How can I send submit buttons'id from ViewUserControl to controler on post action? When I had normal view I could write something like this:

[HttpPost]
public  ActionResult KontaktIzabran(string myId)
{
    //some code 

}   

Now myId is alwasy null....
Here is my UserControl

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<KontaktModel>" %>
<%@ OutputCache Duration="1200" VaryByParam="*" %>
<div id="sign-in-pop" class="popup">    
<div class="modal fat-form">
    <div class="clipper">
        <div class="left"></div>
        <div class="content">Sign In</div>
        <div class="right"></div>
    </div>                    
    <% Html.BeginForm("IzborKontaktaPopUp", "Kontakt"); %>
         <%: Html.ValidationSummary(true) %>
        <div class="editor-field">
            <%: Html.TextBoxFor(model => model.Naziv)%>
            <%: Html.ValidationMessageFor(model => model.Naziv) %>  
            <input type="submit" value="Traži" name="submitButton" id="submitButton" />
            <input type="submit" value="Dodaj novi" name="noviKontakt" />
        </div>
    <% Html.EndForm(); %>
</div>       
</div>   

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赢得她心 2024-10-23 01:25:03
[HttpPost]
public  ActionResult KontaktIzabran(string myId, string noviKontakt)
{
    if (!string.IsNullOrEmpty(noviKontakt))
    {
        // <input type="submit" value="Dodaj novi" name="noviKontakt" />
        // was used to submit the form
    }
    else
    {
        // <input type="submit" value="Traži" name="submitButton" id="submitButton" />
        // was used to submit the form
    }

    ...
}
[HttpPost]
public  ActionResult KontaktIzabran(string myId, string noviKontakt)
{
    if (!string.IsNullOrEmpty(noviKontakt))
    {
        // <input type="submit" value="Dodaj novi" name="noviKontakt" />
        // was used to submit the form
    }
    else
    {
        // <input type="submit" value="Traži" name="submitButton" id="submitButton" />
        // was used to submit the form
    }

    ...
}
疧_╮線 2024-10-23 01:25:03

嗯,看起来您没有名为“myId”的表单字段,因此提交无法将其发送回控制器。相反,它会发回一个包含当前值的 FormCollection:

<%: Html.TextBoxFor(model => model.Naziv)%>
<input type="submit" value="Traži" name="submitButton" id="submitButton" />
<input type="submit" value="Dodaj novi" name="noviKontakt" />

Well it looks like you don't have a form field called "myId", so the submit can't send that back to the controller. Instead it will send back a FormCollection containing the current values of these:

<%: Html.TextBoxFor(model => model.Naziv)%>
<input type="submit" value="Traži" name="submitButton" id="submitButton" />
<input type="submit" value="Dodaj novi" name="noviKontakt" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文