Click here to Skip to main content
15,609,864 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
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:
C#
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);


       }

   }
Posted
Updated 3-Aug-15 5:11am
v2
Comments
Afzaal Ahmad Zeeshan 3-Aug-15 11:08am    
ASP.NET MVC doesn't contain TextBox, those controls belong to Web Forms. Secondly, even if you somehow managed to use a View control in your Model, TextBox won't accept a string as its value, instead it would accept that value in its Text field.

Are you sure the code even compiles?

1 solution

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.
C#
myTextBox.Text = myTextBox.Text + "*";

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900