title: getting error - Unexpected "if" keyword after "@" character. Once inside code, you do not need to prefix constructs like "if" with
body: <p>im getting error in view- ""test1.cshtml"</p>
  
  <p>Unexpected "if" keyword after "@" character.  Once inside code, you do not need to prefix constructs like "if" with</p>
  
  <p><strong>test1.cshtml</strong></p>
  
  <pre><code>    @model WebApplication9.Models.Names
  
  
  @using (Html.BeginForm())
  {
      @Html.TextBoxFor(m =&gt; m.MyName)
  
      &lt;button type="submit"&gt;Submit&lt;/button&gt;
  
      if (!string.IsNullOrWhiteSpace(Model.MyName))
      {
          &lt;p&gt;welcome, your name is @Model.MyName&lt;/p&gt;
      }
  }
  </code></pre>
  
  <p>controller code</p>
  
  <pre><code> public ActionResult test1()
          {
  
              Names name = new Names();
  
              return View(name);
  
              ViewBag.Message = "Your contact page.";
  
              return View();
          }
          [HttpPost]
          public ActionResult test1(string name)
          {
              ViewBag.Message = "Hello what is ur name ???";
              ViewBag.Name = name;
              return View();
          }
  </code></pre>
  
  <p>model code</p>
  
  <pre><code>namespace WebApplication9.Models
  {
      public class Names
      {
          public string MyName { get; set; }
      }
  }
  </code></pre>