---
title: "How to use textbox and ViewBag value in controller method?"  
description: "How to use textbox and ViewBag value in controller method?"  
author: "Mark M"  
published: 2014-11-26  
updated: 2014-11-27  
canonical: https://www.mindstick.com/forum/12693/how-to-use-textbox-and-viewbag-value-in-controller-method  
category: "asp.net"  
tags: ["c#", "controller", "viewbag"]  
reading_time: 1 minute  

---

# How to use textbox and ViewBag value in controller method?

```
@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>}
```

I want to use [textbox value](https://www.mindstick.com/forum/33830/how-to-calculate-data-grid-value-and-textbox-value-on-change-in-vb-dot-net-winform) and [ViewBag](https://www.mindstick.com/forum/155739/define-viewbag-in-mvc) value on my [controller method](https://www.mindstick.com/forum/157312/how-to-call-a-controller-method-after-load-view-successfully-in-mvc-4) which has been defined below?

```
public string getdetail(string Mnumber, string sSongName){    string ss =Mnumber;    string ss1 =sSongName;    return ss;}
```

## Replies

### Reply by Anonymous User

If you want to fill your [textbox](https://www.mindstick.com/forum/12714/dynamic-textbox-in-gridview) with ViewBag [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) try this;

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

If you want to pass that value use hidden [method](https://www.mindstick.com/forum/166/webservice-method) Satpal mentioned about.


---

Original Source: https://www.mindstick.com/forum/12693/how-to-use-textbox-and-viewbag-value-in-controller-method

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
