为什么我没有在我的文本框中输出? [英] Why I Am Not Getting Output In My Textbox?

查看:90
本文介绍了为什么我没有在我的文本框中输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在mvc的文本框中显示菱形图案。当我在控制台上运行我的代码应用程序输出显示在那里,但我没有在mvc屏幕输出。

这是我的控制器:

I want to display diamond pattern in textbox in mvc. When i run my code on console application output is diplayed there but i did not get output on screen in mvc.
Here is my controller:

public class diamondController : Controller
   {
       public ActionResult Diamond()
       {
           DiamondModel model = new DiamondModel();
           return View(model);

       }
       [HttpGet]
       public ActionResult Sum()
       {
           DiamondModel model = new DiamondModel();

           return View(model);
       }
       [HttpPost]
       public ActionResult Diamond(string button, DiamondModel model)
       {
           if (model.textBox.Contains("4") && button == "Submit")
           {
               model.textBox1 = "I love Pakistan";

               model.n = Convert.ToInt32(model.textBox);

               for (int i = 1; i <= model.n; i++)
               {
                   for (int j = 0; j < (model.n - i); j++)
                       model.textBox1 = ("");
                   for (int j = 1; j <= i; j++)
                       model.textBox1 = ("*");
                   for (int k = 1; k < i; k++)
                       model.textBox1 = ("*");

               }

               for (int i = model.n - 1; i >= 1; i--)
               {
                   for (int j = 0; j < (model.n - i); j++)
                       model.textBox1 = (" ");
                   for (int j = 1; j <= i; j++)
                       model.textBox1 = ("*");
                   for (int k = 1; k < i; k++)
                       model.textBox1 = ("*");

               }

           }
               }
           }
           return View(model);


       }

   }

推荐答案

除了 Afzaal Ahmad Zeeshan 优点之外,您应该注意 TextBox 的行为与控制台不一样:为了追加文本到 TextBox 控件,你明确地做了,例如

In addition to Afzaal Ahmad Zeeshan good points, you should note that a TextBox doesn't behave like the Console: in order to append text to a TextBox control you have explicitely do it, e.g.
myTextBox.Text = myTextBox.Text + "*";



或者更好的是,使用 StringBuilder 对象来准备文本,然后分配结果字符串到 TextBox 控件。


Or, better, use a StringBuilder object to prepare your text and then assign the resulting string to the TextBox control.


这篇关于为什么我没有在我的文本框中输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆