1

I'm trying to show some data in some in some bootstrap textboxes.

Normally in Webforms I'd set a dataset and set the .Text properties of textboxes by using something like TextBox.Text=Datatable.Rows[0]["FieldName"].ToString() but being new to MVC got me clueless.

Anyways here is what I have

I have an actionresult like this, where I get the data from DB. Data comes nicely. All I need to do is get them hooked together.

public ActionResult CompanySettings()
        {
            ClaimsIdentity identity = (ClaimsIdentity)User.Identity;
            int CompanyId = Convert.ToInt32(identity.FindFirst("CompanyId").Value);
            //-----------------------------
            ViewBag.CompanyId = CompanyId;
            ViewBag.Page = "Inbox";
            string Name = identity.Name;
            string CompanyName = identity.FindFirst("CompanyName").Value;



            ViewBag.Name = Name;
            ViewBag.CompanyName = CompanyName;
            //-----------------------------

            DataSet ds = CompanyDB.Company_Get_Info(CompanyId);
            return View();
        }

and my ViewModel (showing only one field as a n example)

public class CompanySettingViewModel
    {
        [Display(Name = "CompanyType")]
        public CompanyType CompanyType { get; set; }

        //and many more fields like this.
    }

I'm posting my html part too in any case

<table>
  <tr>
    <td>
      <div class="registerbox-textbox">
          <h6>Company Type</h6>
       @Html.Bootstrap().TextBoxFor(t=>t.CompanyType).Placeholder("FirmaTipi")
      </div>
    </td>
//again many repeating same type fields inside a table
<tr>
<table>

This is probably something very simple and easy but I'm stuck. Does anyone have any idea?

1 Answer 1

4
public ActionResult CompanySettings()
    {
        ClaimsIdentity identity = (ClaimsIdentity)User.Identity;
        int CompanyId = Convert.ToInt32(identity.FindFirst("CompanyId").Value);
        //-----------------------------
        ViewBag.CompanyId = CompanyId;
        ViewBag.Page = "Inbox";
        string Name = identity.Name;
        string CompanyName = identity.FindFirst("CompanyName").Value;



        ViewBag.Name = Name;
        ViewBag.CompanyName = CompanyName;
        //-----------------------------

        DataSet ds = CompanyDB.Company_Get_Info(CompanyId);
        CompanySettingViewModel NewModel= new CompanySettingViewModel();
        NewModel.CompanyType = "AnyValue" //Pass the Company Type value to model 
        return View(NewModel);
    }

and your view will be

  <table>
  <tr>
    <td>
      <div class="registerbox-textbox">
          <h6>Company Type</h6>
       @Html.TextBoxFor(t=>t.CompanyType,  new { @placeholder = "FirmaTipi" })
      </div>
    </td>
//again many repeating same type fields inside a table
<tr>
<table>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.