【问题标题】:How to use textbox and ViewBag value in controller method?如何在控制器方法中使用文本框和 ViewBag 值?
【发布时间】:2014-03-10 12:45:53
【问题描述】:
@using (Html.BeginForm("sendcode", "Home", FormMethod.Post))
{
<div class="selected">You Selected:</div>
<div class="sname">@ViewBag.selectsong</div>
<div class="enter" style="width:458px;height:37px; text-align:left;">
<div class="selected">Enter your mobile number</div>
<div class="mobileno">
<div><div class="spann">+91</div><input name="MNumber" type="text" class="mobileinput"/></div></div>`enter code here`
<div class="confirm"><input name="" type="button" class="confirmb"value="Confirm"onclick="location.href='@Url.Action("getdetail", "Home" )'/>
</div>
<div class="applicablee">* charges applicable as per your mobile operators</div>
</div>
}

我想在下面定义的控制器方法上使用文本框值和 ViewBag 值?

public string getdetail(string Mnumber, string sSongName)
{
    string ss = Mnumber;
    string ss1 = sSongName;
    return ss;
}

【问题讨论】:

  • 您可以使用隐藏。只需添加一个隐藏的&lt;input name="sSongName" type="hidden" value="@ViewBag.selectsong"/&gt;
  • 回发,控制器可以接他们。

标签: c# asp.net asp.net-mvc-3 razor


【解决方案1】:

viewbag 是一种单向属性

如果你想返回它的值,你必须将你的变量定义为你的模型的一个属性 然后将模型作为参数传递给您的操作

【讨论】:

    【解决方案2】:

    如果你想用 ViewBag 值填充你的文本框试试这个;

    <input type="textbox" id="aa" name="aa" value="@Viewbag.X"/>
    

    如果您想传递该值,请使用 Satpal 提到的隐藏方法。

    【讨论】:

      猜你喜欢
      • 2017-04-21
      • 1970-01-01
      • 1970-01-01
      • 2021-02-09
      • 1970-01-01
      • 2018-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多