Pass value from Controller to @HTML.TextBoxA potentially dangerous Request.Form value was detected from the clientasp.net mvc - obtain values from a bunch of inputs selectivelyASP.NET MVC Unbind Action ParameterHow do I get the value of an input of html.textbox in ASP.NET MVC 2Is viewbag the best option?TextBox(HtmlHelper, String) - is view model also searched for a value?mapping json returned from controller to strongly typed viewget a variable passed to my controller from a textboxMove Processing from the View to a controllerProblem adding string value to ViewBag from an MVC Action using TempData

Delete elements less than the last largest element

How do I talk to my wife about unrealistic expectations?

Decrease spacing between a bullet point and its subbullet point

Is there a formal/better word than "skyrocket" for the given context?

Need a non-volatile memory IC with near unlimited read/write operations capability

Strong Password Detection in Python

Moving millions of files to a different directory with specfic name patterns

Why the Cauchy Distribution is so useful?

Write a function

How do resistors generate different heat if we make the current fixed and changed the voltage and resistance? Notice the flow of charge is constant

What do you call a situation where you have choices but no good choice?

Why am I getting unevenly-spread results when using $RANDOM?

What are the effects of abstaining from eating a certain flavor?

Users forgotting to regenerate PDF before sending it

Findminimum of Integral

How to evaluate the performance of open source solver?

How do ballistic trajectories work in a ring world?

My professor has told me he will be the corresponding author. Will it hurt my future career?

How to use Adostop Eco stop bath?

US citizen traveling with Peruvian passport

Is it okay to use open source code to do an interview task?

How should I ask for a "pint" in countries that use metric?

Why did Old English lose both thorn and eth?

Is it possible for a character at any level to cast all 44 Cantrips in one week without Magic Items?



Pass value from Controller to @HTML.TextBox


A potentially dangerous Request.Form value was detected from the clientasp.net mvc - obtain values from a bunch of inputs selectivelyASP.NET MVC Unbind Action ParameterHow do I get the value of an input of html.textbox in ASP.NET MVC 2Is viewbag the best option?TextBox(HtmlHelper, String) - is view model also searched for a value?mapping json returned from controller to strongly typed viewget a variable passed to my controller from a textboxMove Processing from the View to a controllerProblem adding string value to ViewBag from an MVC Action using TempData






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have a search functionality in the Index page with search options that results in Grid with Details link(another page), I am redirecting to Details page. From details page to Index page I need to retain the search criteria.



I am using ViewBag to store the values and and able to see the value in the Index.cshtml but the value is not assigned in the TextBox



Controller:



public ActionResult Index(string type)

try

if (type == "Search")

ViewBag.Id = 100;
return View();


catch (Exception ex)

ViewBag.ErrorMessage = "An error occurred: " + ex.Message;
return View();




Index.cshtml:



@Html.TextBox("txtID", (string)ViewBag.Id, new id = "txtID", @class = "input" )


Generated HTML:



<input class="inputBox" id="txtID" name="txtID" type="text" value="100">


The generated output is having the value as 100, but the value is not assigned to the Textbox and it is displaying Empty/Null.



How to assign the ViewBag value to @HTML.TextBox










share|improve this question
























  • I have used the suggested above and the generated html is <input type="text" id="txtID" name="txtID" value="100"> Still the value is not displaying in the textbox

    – Andy
    Mar 25 at 23:05












  • see this example (dotnetfiddle.net/Pyk2db)

    – Ajeet Kumar
    Mar 26 at 3:36











  • Thank you Ajeet Kumar. your example is perfect, but still the value is not visible in the TextBox. The generated HTML is same, still the value is not being assigned to the textbox.

    – Andy
    Mar 26 at 7:53

















0















I have a search functionality in the Index page with search options that results in Grid with Details link(another page), I am redirecting to Details page. From details page to Index page I need to retain the search criteria.



I am using ViewBag to store the values and and able to see the value in the Index.cshtml but the value is not assigned in the TextBox



Controller:



public ActionResult Index(string type)

try

if (type == "Search")

ViewBag.Id = 100;
return View();


catch (Exception ex)

ViewBag.ErrorMessage = "An error occurred: " + ex.Message;
return View();




Index.cshtml:



@Html.TextBox("txtID", (string)ViewBag.Id, new id = "txtID", @class = "input" )


Generated HTML:



<input class="inputBox" id="txtID" name="txtID" type="text" value="100">


The generated output is having the value as 100, but the value is not assigned to the Textbox and it is displaying Empty/Null.



How to assign the ViewBag value to @HTML.TextBox










share|improve this question
























  • I have used the suggested above and the generated html is <input type="text" id="txtID" name="txtID" value="100"> Still the value is not displaying in the textbox

    – Andy
    Mar 25 at 23:05












  • see this example (dotnetfiddle.net/Pyk2db)

    – Ajeet Kumar
    Mar 26 at 3:36











  • Thank you Ajeet Kumar. your example is perfect, but still the value is not visible in the TextBox. The generated HTML is same, still the value is not being assigned to the textbox.

    – Andy
    Mar 26 at 7:53













0












0








0








I have a search functionality in the Index page with search options that results in Grid with Details link(another page), I am redirecting to Details page. From details page to Index page I need to retain the search criteria.



I am using ViewBag to store the values and and able to see the value in the Index.cshtml but the value is not assigned in the TextBox



Controller:



public ActionResult Index(string type)

try

if (type == "Search")

ViewBag.Id = 100;
return View();


catch (Exception ex)

ViewBag.ErrorMessage = "An error occurred: " + ex.Message;
return View();




Index.cshtml:



@Html.TextBox("txtID", (string)ViewBag.Id, new id = "txtID", @class = "input" )


Generated HTML:



<input class="inputBox" id="txtID" name="txtID" type="text" value="100">


The generated output is having the value as 100, but the value is not assigned to the Textbox and it is displaying Empty/Null.



How to assign the ViewBag value to @HTML.TextBox










share|improve this question
















I have a search functionality in the Index page with search options that results in Grid with Details link(another page), I am redirecting to Details page. From details page to Index page I need to retain the search criteria.



I am using ViewBag to store the values and and able to see the value in the Index.cshtml but the value is not assigned in the TextBox



Controller:



public ActionResult Index(string type)

try

if (type == "Search")

ViewBag.Id = 100;
return View();


catch (Exception ex)

ViewBag.ErrorMessage = "An error occurred: " + ex.Message;
return View();




Index.cshtml:



@Html.TextBox("txtID", (string)ViewBag.Id, new id = "txtID", @class = "input" )


Generated HTML:



<input class="inputBox" id="txtID" name="txtID" type="text" value="100">


The generated output is having the value as 100, but the value is not assigned to the Textbox and it is displaying Empty/Null.



How to assign the ViewBag value to @HTML.TextBox







asp.net-mvc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 22:31









Peter B

14.2k5 gold badges20 silver badges47 bronze badges




14.2k5 gold badges20 silver badges47 bronze badges










asked Mar 25 at 22:11









AndyAndy

11 bronze badge




11 bronze badge












  • I have used the suggested above and the generated html is <input type="text" id="txtID" name="txtID" value="100"> Still the value is not displaying in the textbox

    – Andy
    Mar 25 at 23:05












  • see this example (dotnetfiddle.net/Pyk2db)

    – Ajeet Kumar
    Mar 26 at 3:36











  • Thank you Ajeet Kumar. your example is perfect, but still the value is not visible in the TextBox. The generated HTML is same, still the value is not being assigned to the textbox.

    – Andy
    Mar 26 at 7:53

















  • I have used the suggested above and the generated html is <input type="text" id="txtID" name="txtID" value="100"> Still the value is not displaying in the textbox

    – Andy
    Mar 25 at 23:05












  • see this example (dotnetfiddle.net/Pyk2db)

    – Ajeet Kumar
    Mar 26 at 3:36











  • Thank you Ajeet Kumar. your example is perfect, but still the value is not visible in the TextBox. The generated HTML is same, still the value is not being assigned to the textbox.

    – Andy
    Mar 26 at 7:53
















I have used the suggested above and the generated html is <input type="text" id="txtID" name="txtID" value="100"> Still the value is not displaying in the textbox

– Andy
Mar 25 at 23:05






I have used the suggested above and the generated html is <input type="text" id="txtID" name="txtID" value="100"> Still the value is not displaying in the textbox

– Andy
Mar 25 at 23:05














see this example (dotnetfiddle.net/Pyk2db)

– Ajeet Kumar
Mar 26 at 3:36





see this example (dotnetfiddle.net/Pyk2db)

– Ajeet Kumar
Mar 26 at 3:36













Thank you Ajeet Kumar. your example is perfect, but still the value is not visible in the TextBox. The generated HTML is same, still the value is not being assigned to the textbox.

– Andy
Mar 26 at 7:53





Thank you Ajeet Kumar. your example is perfect, but still the value is not visible in the TextBox. The generated HTML is same, still the value is not being assigned to the textbox.

– Andy
Mar 26 at 7:53












0






active

oldest

votes










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55347153%2fpass-value-from-controller-to-html-textbox%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55347153%2fpass-value-from-controller-to-html-textbox%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript