MVC: split string from model in multiple text boxesHow do you create a dropdownlist from an enum in ASP.NET MVC?How do you handle multiple submit buttons in ASP.NET MVC Framework?In MVC, how do I return a string result?Easiest way to split a string on newlines in .NET?C# Split A String By Another StringHow to control both the width and decimal places for a text box?ASP.NET MVC 5 Scaffolding not creating elements for enum propertyMultiple lines instead of single line in HtmlEditFor() function? ASP.NET MVC 5 RazorHow to use datetime picker as editortemplatecant set the size of a multi line text box mvc

Does the reader need to like the PoV character?

Review your own paper in Mathematics

Giving feedback to someone without sounding prejudiced

What (the heck) is a Super Worm Equinox Moon?

How to draw a matrix with arrows in limited space

How can ping know if my host is down

Which Article Helped Get Rid of Technobabble in RPGs?

What is the English pronunciation of "pain au chocolat"?

What is the difference between lands and mana?

Is this toilet slogan correct usage of the English language?

What fields between the rationals and the reals allow a good notion of 2D distance?

Is my low blitz game drawing rate at www.chess.com an indicator that I am weak in chess?

awk assign to multiple variables at once

US tourist/student visa

Find the next value of this number series

Why do ¬, ∀ and ∃ have the same precedence?

Creating two special characters

Doesn't the system of the Supreme Court oppose justice?

Quoting Keynes in a lecture

Taxes on Dividends in a Roth IRA

How do you make your own symbol when Detexify fails?

How to convince somebody that he is fit for something else, but not this job?

"It doesn't matter" or "it won't matter"?

Pre-mixing cryogenic fuels and using only one fuel tank



MVC: split string from model in multiple text boxes


How do you create a dropdownlist from an enum in ASP.NET MVC?How do you handle multiple submit buttons in ASP.NET MVC Framework?In MVC, how do I return a string result?Easiest way to split a string on newlines in .NET?C# Split A String By Another StringHow to control both the width and decimal places for a text box?ASP.NET MVC 5 Scaffolding not creating elements for enum propertyMultiple lines instead of single line in HtmlEditFor() function? ASP.NET MVC 5 RazorHow to use datetime picker as editortemplatecant set the size of a multi line text box mvc













0















I have a model:



public class Data

public int id get; set;
public string BBBCode get; set;



Part of view:



<div class="col-md-10">
@Html.EditorFor(model => model.BBBCode, new htmlAttributes = new @class = "form-control" )
@Html.ValidationMessageFor(model => model.BBBCode, "", new @class = "text-danger" )
</div>


for this model, Visual studio created an edit view with text box for the BBBCode member. But I need to split BBBCode in two textboxes, first text box should have maximum 4 characters and the second text box should contain the rest of the characters. Is there a way to achieve this automatically or without any javascript code and without modifying the model?










share|improve this question

















  • 1





    have your tried custom editor template ?

    – Suren Srapyan
    Nov 20 '15 at 13:33











  • @SurenSrapyan No. Can you please send me a link or something? I'm new to MVC and I know only the basic stuff. Thanks

    – Buda Gavril
    Nov 20 '15 at 13:34












  • try this: codeguru.com/csharp/.net/net_asp/mvc/… and you can search for this like: MVC Editor Templates

    – Suren Srapyan
    Nov 20 '15 at 13:37











  • but as an advice I'll say you.Your View is wanted 2 textboxes for your model.But your model has only the one which must be changed.So it will be good if you make a ViewModel(about ViewModel search).In ViewModel there is everything that your View want.So in the VIewModel you can have 2 separate strings(BBBCode pieces) and give your View's Model to that ViewModel

    – Suren Srapyan
    Nov 20 '15 at 13:40















0















I have a model:



public class Data

public int id get; set;
public string BBBCode get; set;



Part of view:



<div class="col-md-10">
@Html.EditorFor(model => model.BBBCode, new htmlAttributes = new @class = "form-control" )
@Html.ValidationMessageFor(model => model.BBBCode, "", new @class = "text-danger" )
</div>


for this model, Visual studio created an edit view with text box for the BBBCode member. But I need to split BBBCode in two textboxes, first text box should have maximum 4 characters and the second text box should contain the rest of the characters. Is there a way to achieve this automatically or without any javascript code and without modifying the model?










share|improve this question

















  • 1





    have your tried custom editor template ?

    – Suren Srapyan
    Nov 20 '15 at 13:33











  • @SurenSrapyan No. Can you please send me a link or something? I'm new to MVC and I know only the basic stuff. Thanks

    – Buda Gavril
    Nov 20 '15 at 13:34












  • try this: codeguru.com/csharp/.net/net_asp/mvc/… and you can search for this like: MVC Editor Templates

    – Suren Srapyan
    Nov 20 '15 at 13:37











  • but as an advice I'll say you.Your View is wanted 2 textboxes for your model.But your model has only the one which must be changed.So it will be good if you make a ViewModel(about ViewModel search).In ViewModel there is everything that your View want.So in the VIewModel you can have 2 separate strings(BBBCode pieces) and give your View's Model to that ViewModel

    – Suren Srapyan
    Nov 20 '15 at 13:40













0












0








0








I have a model:



public class Data

public int id get; set;
public string BBBCode get; set;



Part of view:



<div class="col-md-10">
@Html.EditorFor(model => model.BBBCode, new htmlAttributes = new @class = "form-control" )
@Html.ValidationMessageFor(model => model.BBBCode, "", new @class = "text-danger" )
</div>


for this model, Visual studio created an edit view with text box for the BBBCode member. But I need to split BBBCode in two textboxes, first text box should have maximum 4 characters and the second text box should contain the rest of the characters. Is there a way to achieve this automatically or without any javascript code and without modifying the model?










share|improve this question














I have a model:



public class Data

public int id get; set;
public string BBBCode get; set;



Part of view:



<div class="col-md-10">
@Html.EditorFor(model => model.BBBCode, new htmlAttributes = new @class = "form-control" )
@Html.ValidationMessageFor(model => model.BBBCode, "", new @class = "text-danger" )
</div>


for this model, Visual studio created an edit view with text box for the BBBCode member. But I need to split BBBCode in two textboxes, first text box should have maximum 4 characters and the second text box should contain the rest of the characters. Is there a way to achieve this automatically or without any javascript code and without modifying the model?







c# asp.net-mvc razor






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '15 at 13:32









Buda GavrilBuda Gavril

11.4k30100151




11.4k30100151







  • 1





    have your tried custom editor template ?

    – Suren Srapyan
    Nov 20 '15 at 13:33











  • @SurenSrapyan No. Can you please send me a link or something? I'm new to MVC and I know only the basic stuff. Thanks

    – Buda Gavril
    Nov 20 '15 at 13:34












  • try this: codeguru.com/csharp/.net/net_asp/mvc/… and you can search for this like: MVC Editor Templates

    – Suren Srapyan
    Nov 20 '15 at 13:37











  • but as an advice I'll say you.Your View is wanted 2 textboxes for your model.But your model has only the one which must be changed.So it will be good if you make a ViewModel(about ViewModel search).In ViewModel there is everything that your View want.So in the VIewModel you can have 2 separate strings(BBBCode pieces) and give your View's Model to that ViewModel

    – Suren Srapyan
    Nov 20 '15 at 13:40












  • 1





    have your tried custom editor template ?

    – Suren Srapyan
    Nov 20 '15 at 13:33











  • @SurenSrapyan No. Can you please send me a link or something? I'm new to MVC and I know only the basic stuff. Thanks

    – Buda Gavril
    Nov 20 '15 at 13:34












  • try this: codeguru.com/csharp/.net/net_asp/mvc/… and you can search for this like: MVC Editor Templates

    – Suren Srapyan
    Nov 20 '15 at 13:37











  • but as an advice I'll say you.Your View is wanted 2 textboxes for your model.But your model has only the one which must be changed.So it will be good if you make a ViewModel(about ViewModel search).In ViewModel there is everything that your View want.So in the VIewModel you can have 2 separate strings(BBBCode pieces) and give your View's Model to that ViewModel

    – Suren Srapyan
    Nov 20 '15 at 13:40







1




1





have your tried custom editor template ?

– Suren Srapyan
Nov 20 '15 at 13:33





have your tried custom editor template ?

– Suren Srapyan
Nov 20 '15 at 13:33













@SurenSrapyan No. Can you please send me a link or something? I'm new to MVC and I know only the basic stuff. Thanks

– Buda Gavril
Nov 20 '15 at 13:34






@SurenSrapyan No. Can you please send me a link or something? I'm new to MVC and I know only the basic stuff. Thanks

– Buda Gavril
Nov 20 '15 at 13:34














try this: codeguru.com/csharp/.net/net_asp/mvc/… and you can search for this like: MVC Editor Templates

– Suren Srapyan
Nov 20 '15 at 13:37





try this: codeguru.com/csharp/.net/net_asp/mvc/… and you can search for this like: MVC Editor Templates

– Suren Srapyan
Nov 20 '15 at 13:37













but as an advice I'll say you.Your View is wanted 2 textboxes for your model.But your model has only the one which must be changed.So it will be good if you make a ViewModel(about ViewModel search).In ViewModel there is everything that your View want.So in the VIewModel you can have 2 separate strings(BBBCode pieces) and give your View's Model to that ViewModel

– Suren Srapyan
Nov 20 '15 at 13:40





but as an advice I'll say you.Your View is wanted 2 textboxes for your model.But your model has only the one which must be changed.So it will be good if you make a ViewModel(about ViewModel search).In ViewModel there is everything that your View want.So in the VIewModel you can have 2 separate strings(BBBCode pieces) and give your View's Model to that ViewModel

– Suren Srapyan
Nov 20 '15 at 13:40












4 Answers
4






active

oldest

votes


















0














Ideally, your viewmodel should correspond to the form you actually render. Mostly if Data belongs to business logic. I.e:



public class Data

public int id get; set;
public string BBBCode get; set;


public class DataViewModel

public DataViewModel()



public DataViewModel(Data data)

id = data.id ;
BBBCodePartOne = ... ;
BBBCodePartTwo = ... ;


public int id get; set;
public string BBBCodePartOne get; set;
public string BBBCodePartTwo get; set;

public Data ToData()

return new Data() id = id, BBBCode = BBBCodePartOne + BBBCodePartTwo ;







share|improve this answer
































    0














    It's better to do it in your View model i mean like this:



    public class Data

    public static char Separator = '-'; //here is your separator
    public int id get; set;
    public string BBBBegin get; set;
    public string BBBEnd get; set;
    public string BBBCode get return BBBBegin + Separator + BBBEnd;



    Now on your View you always can do it like this:



    <div class="col-md-10">
    @Html.EditorFor(model => model.BBBBegin, new htmlAttributes = new @class = "form-control" )
    @Html.EditorFor(model => model.BBBEnd, new htmlAttributes = new @class = "form-control" )
    @Html.ValidationMessageFor(model => model.BBBBegin, "", new @class = "text-danger" )
    @Html.ValidationMessageFor(model => model.BBBEnd, "", new @class = "text-danger" )
    </div>


    And when you post it to controller you always can get full BBBCode from BBBCode property.






    share|improve this answer























    • and when I will want to save the model, will it automaticaly populate BBBCode with the text from those two text boxes?

      – Buda Gavril
      Nov 20 '15 at 13:44











    • @BudaGavril you should just understand wht will happened. You post form with your textboxes, then MVC will bind values to BBBBegin BBBEnd properties. Then you can just get full code from BBBCode property. i suppose it's pretty clear how it will work

      – teo van kot
      Nov 20 '15 at 13:46











    • I understand that, but I've asked if there's a way to bind automatically those two text boxes to my property when the model is validated.

      – Buda Gavril
      Nov 20 '15 at 13:52











    • @BudaGavril yes there is. You should create your CustomModelBinder but it's really now wotrh it. It's better to extend existing model or create ViewModel like @Ksv3n advice you

      – teo van kot
      Nov 20 '15 at 13:54


















    0














    You should use two property in your model.



    public class Data

    public int id get; set;
    public string BBBCode1 get; set;
    public string BBBCode2 get; set;


    <div class="col-md-10">
    @Html.EditorFor(model => model.BBBCode1, new htmlAttributes = new @class = "form-control" )
    @Html.ValidationMessageFor(model => model.BBBCode1, "", new @class = "text-danger" )
    </div>
    <div class="col-md-10">
    @Html.EditorFor(model => model.BBBCode2, new htmlAttributes = new @class = "form-control" )
    @Html.ValidationMessageFor(model => model.BBBCode2, "", new @class = "text-danger" )
    </div>


    in your controller



    public ActionResult Index(Data model)
    var bbcCode = model.BBCCode1 + model.BBCCode2;






    share|improve this answer























    • My model is an entity and it has only one member for this code and I want to be automatically populated when I edit the data.

      – Buda Gavril
      Nov 20 '15 at 13:45











    • you shouldn't use your entity as a view model. You should create a new view model class so you should use it in your view as model. After that populate data in your controller like my sample code.

      – Yargicx
      Nov 20 '15 at 14:11


















    0














    If you don't want to change the Model (no judgement)
    I used these two in my input field, one for both parts of the value:



    <div>@Html.TextBoxFor(m => m.Betrag, new @Value = Model.Betrag.ToString().Split(',').GetValue(0) )</div>

    <div>@Html.TextBoxFor(m => m.Betrag, new @Value = Model.Betrag.ToString().Split(',').GetValue(1) )</div>


    This simply splits up a value like '15,00' into a '15' and '00', you can then join the values together again afterwards with some Javascript and JQuery. This works great for me.






    share|improve this answer










    New contributor




    Bradley Weibel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.



















      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%2f33828004%2fmvc-split-string-from-model-in-multiple-text-boxes%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Ideally, your viewmodel should correspond to the form you actually render. Mostly if Data belongs to business logic. I.e:



      public class Data

      public int id get; set;
      public string BBBCode get; set;


      public class DataViewModel

      public DataViewModel()



      public DataViewModel(Data data)

      id = data.id ;
      BBBCodePartOne = ... ;
      BBBCodePartTwo = ... ;


      public int id get; set;
      public string BBBCodePartOne get; set;
      public string BBBCodePartTwo get; set;

      public Data ToData()

      return new Data() id = id, BBBCode = BBBCodePartOne + BBBCodePartTwo ;







      share|improve this answer





























        0














        Ideally, your viewmodel should correspond to the form you actually render. Mostly if Data belongs to business logic. I.e:



        public class Data

        public int id get; set;
        public string BBBCode get; set;


        public class DataViewModel

        public DataViewModel()



        public DataViewModel(Data data)

        id = data.id ;
        BBBCodePartOne = ... ;
        BBBCodePartTwo = ... ;


        public int id get; set;
        public string BBBCodePartOne get; set;
        public string BBBCodePartTwo get; set;

        public Data ToData()

        return new Data() id = id, BBBCode = BBBCodePartOne + BBBCodePartTwo ;







        share|improve this answer



























          0












          0








          0







          Ideally, your viewmodel should correspond to the form you actually render. Mostly if Data belongs to business logic. I.e:



          public class Data

          public int id get; set;
          public string BBBCode get; set;


          public class DataViewModel

          public DataViewModel()



          public DataViewModel(Data data)

          id = data.id ;
          BBBCodePartOne = ... ;
          BBBCodePartTwo = ... ;


          public int id get; set;
          public string BBBCodePartOne get; set;
          public string BBBCodePartTwo get; set;

          public Data ToData()

          return new Data() id = id, BBBCode = BBBCodePartOne + BBBCodePartTwo ;







          share|improve this answer















          Ideally, your viewmodel should correspond to the form you actually render. Mostly if Data belongs to business logic. I.e:



          public class Data

          public int id get; set;
          public string BBBCode get; set;


          public class DataViewModel

          public DataViewModel()



          public DataViewModel(Data data)

          id = data.id ;
          BBBCodePartOne = ... ;
          BBBCodePartTwo = ... ;


          public int id get; set;
          public string BBBCodePartOne get; set;
          public string BBBCodePartTwo get; set;

          public Data ToData()

          return new Data() id = id, BBBCode = BBBCodePartOne + BBBCodePartTwo ;








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 20 '15 at 13:46

























          answered Nov 20 '15 at 13:41









          Mr. FahrenheitMr. Fahrenheit

          9,23421541




          9,23421541























              0














              It's better to do it in your View model i mean like this:



              public class Data

              public static char Separator = '-'; //here is your separator
              public int id get; set;
              public string BBBBegin get; set;
              public string BBBEnd get; set;
              public string BBBCode get return BBBBegin + Separator + BBBEnd;



              Now on your View you always can do it like this:



              <div class="col-md-10">
              @Html.EditorFor(model => model.BBBBegin, new htmlAttributes = new @class = "form-control" )
              @Html.EditorFor(model => model.BBBEnd, new htmlAttributes = new @class = "form-control" )
              @Html.ValidationMessageFor(model => model.BBBBegin, "", new @class = "text-danger" )
              @Html.ValidationMessageFor(model => model.BBBEnd, "", new @class = "text-danger" )
              </div>


              And when you post it to controller you always can get full BBBCode from BBBCode property.






              share|improve this answer























              • and when I will want to save the model, will it automaticaly populate BBBCode with the text from those two text boxes?

                – Buda Gavril
                Nov 20 '15 at 13:44











              • @BudaGavril you should just understand wht will happened. You post form with your textboxes, then MVC will bind values to BBBBegin BBBEnd properties. Then you can just get full code from BBBCode property. i suppose it's pretty clear how it will work

                – teo van kot
                Nov 20 '15 at 13:46











              • I understand that, but I've asked if there's a way to bind automatically those two text boxes to my property when the model is validated.

                – Buda Gavril
                Nov 20 '15 at 13:52











              • @BudaGavril yes there is. You should create your CustomModelBinder but it's really now wotrh it. It's better to extend existing model or create ViewModel like @Ksv3n advice you

                – teo van kot
                Nov 20 '15 at 13:54















              0














              It's better to do it in your View model i mean like this:



              public class Data

              public static char Separator = '-'; //here is your separator
              public int id get; set;
              public string BBBBegin get; set;
              public string BBBEnd get; set;
              public string BBBCode get return BBBBegin + Separator + BBBEnd;



              Now on your View you always can do it like this:



              <div class="col-md-10">
              @Html.EditorFor(model => model.BBBBegin, new htmlAttributes = new @class = "form-control" )
              @Html.EditorFor(model => model.BBBEnd, new htmlAttributes = new @class = "form-control" )
              @Html.ValidationMessageFor(model => model.BBBBegin, "", new @class = "text-danger" )
              @Html.ValidationMessageFor(model => model.BBBEnd, "", new @class = "text-danger" )
              </div>


              And when you post it to controller you always can get full BBBCode from BBBCode property.






              share|improve this answer























              • and when I will want to save the model, will it automaticaly populate BBBCode with the text from those two text boxes?

                – Buda Gavril
                Nov 20 '15 at 13:44











              • @BudaGavril you should just understand wht will happened. You post form with your textboxes, then MVC will bind values to BBBBegin BBBEnd properties. Then you can just get full code from BBBCode property. i suppose it's pretty clear how it will work

                – teo van kot
                Nov 20 '15 at 13:46











              • I understand that, but I've asked if there's a way to bind automatically those two text boxes to my property when the model is validated.

                – Buda Gavril
                Nov 20 '15 at 13:52











              • @BudaGavril yes there is. You should create your CustomModelBinder but it's really now wotrh it. It's better to extend existing model or create ViewModel like @Ksv3n advice you

                – teo van kot
                Nov 20 '15 at 13:54













              0












              0








              0







              It's better to do it in your View model i mean like this:



              public class Data

              public static char Separator = '-'; //here is your separator
              public int id get; set;
              public string BBBBegin get; set;
              public string BBBEnd get; set;
              public string BBBCode get return BBBBegin + Separator + BBBEnd;



              Now on your View you always can do it like this:



              <div class="col-md-10">
              @Html.EditorFor(model => model.BBBBegin, new htmlAttributes = new @class = "form-control" )
              @Html.EditorFor(model => model.BBBEnd, new htmlAttributes = new @class = "form-control" )
              @Html.ValidationMessageFor(model => model.BBBBegin, "", new @class = "text-danger" )
              @Html.ValidationMessageFor(model => model.BBBEnd, "", new @class = "text-danger" )
              </div>


              And when you post it to controller you always can get full BBBCode from BBBCode property.






              share|improve this answer













              It's better to do it in your View model i mean like this:



              public class Data

              public static char Separator = '-'; //here is your separator
              public int id get; set;
              public string BBBBegin get; set;
              public string BBBEnd get; set;
              public string BBBCode get return BBBBegin + Separator + BBBEnd;



              Now on your View you always can do it like this:



              <div class="col-md-10">
              @Html.EditorFor(model => model.BBBBegin, new htmlAttributes = new @class = "form-control" )
              @Html.EditorFor(model => model.BBBEnd, new htmlAttributes = new @class = "form-control" )
              @Html.ValidationMessageFor(model => model.BBBBegin, "", new @class = "text-danger" )
              @Html.ValidationMessageFor(model => model.BBBEnd, "", new @class = "text-danger" )
              </div>


              And when you post it to controller you always can get full BBBCode from BBBCode property.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 20 '15 at 13:41









              teo van kotteo van kot

              11.3k103357




              11.3k103357












              • and when I will want to save the model, will it automaticaly populate BBBCode with the text from those two text boxes?

                – Buda Gavril
                Nov 20 '15 at 13:44











              • @BudaGavril you should just understand wht will happened. You post form with your textboxes, then MVC will bind values to BBBBegin BBBEnd properties. Then you can just get full code from BBBCode property. i suppose it's pretty clear how it will work

                – teo van kot
                Nov 20 '15 at 13:46











              • I understand that, but I've asked if there's a way to bind automatically those two text boxes to my property when the model is validated.

                – Buda Gavril
                Nov 20 '15 at 13:52











              • @BudaGavril yes there is. You should create your CustomModelBinder but it's really now wotrh it. It's better to extend existing model or create ViewModel like @Ksv3n advice you

                – teo van kot
                Nov 20 '15 at 13:54

















              • and when I will want to save the model, will it automaticaly populate BBBCode with the text from those two text boxes?

                – Buda Gavril
                Nov 20 '15 at 13:44











              • @BudaGavril you should just understand wht will happened. You post form with your textboxes, then MVC will bind values to BBBBegin BBBEnd properties. Then you can just get full code from BBBCode property. i suppose it's pretty clear how it will work

                – teo van kot
                Nov 20 '15 at 13:46











              • I understand that, but I've asked if there's a way to bind automatically those two text boxes to my property when the model is validated.

                – Buda Gavril
                Nov 20 '15 at 13:52











              • @BudaGavril yes there is. You should create your CustomModelBinder but it's really now wotrh it. It's better to extend existing model or create ViewModel like @Ksv3n advice you

                – teo van kot
                Nov 20 '15 at 13:54
















              and when I will want to save the model, will it automaticaly populate BBBCode with the text from those two text boxes?

              – Buda Gavril
              Nov 20 '15 at 13:44





              and when I will want to save the model, will it automaticaly populate BBBCode with the text from those two text boxes?

              – Buda Gavril
              Nov 20 '15 at 13:44













              @BudaGavril you should just understand wht will happened. You post form with your textboxes, then MVC will bind values to BBBBegin BBBEnd properties. Then you can just get full code from BBBCode property. i suppose it's pretty clear how it will work

              – teo van kot
              Nov 20 '15 at 13:46





              @BudaGavril you should just understand wht will happened. You post form with your textboxes, then MVC will bind values to BBBBegin BBBEnd properties. Then you can just get full code from BBBCode property. i suppose it's pretty clear how it will work

              – teo van kot
              Nov 20 '15 at 13:46













              I understand that, but I've asked if there's a way to bind automatically those two text boxes to my property when the model is validated.

              – Buda Gavril
              Nov 20 '15 at 13:52





              I understand that, but I've asked if there's a way to bind automatically those two text boxes to my property when the model is validated.

              – Buda Gavril
              Nov 20 '15 at 13:52













              @BudaGavril yes there is. You should create your CustomModelBinder but it's really now wotrh it. It's better to extend existing model or create ViewModel like @Ksv3n advice you

              – teo van kot
              Nov 20 '15 at 13:54





              @BudaGavril yes there is. You should create your CustomModelBinder but it's really now wotrh it. It's better to extend existing model or create ViewModel like @Ksv3n advice you

              – teo van kot
              Nov 20 '15 at 13:54











              0














              You should use two property in your model.



              public class Data

              public int id get; set;
              public string BBBCode1 get; set;
              public string BBBCode2 get; set;


              <div class="col-md-10">
              @Html.EditorFor(model => model.BBBCode1, new htmlAttributes = new @class = "form-control" )
              @Html.ValidationMessageFor(model => model.BBBCode1, "", new @class = "text-danger" )
              </div>
              <div class="col-md-10">
              @Html.EditorFor(model => model.BBBCode2, new htmlAttributes = new @class = "form-control" )
              @Html.ValidationMessageFor(model => model.BBBCode2, "", new @class = "text-danger" )
              </div>


              in your controller



              public ActionResult Index(Data model)
              var bbcCode = model.BBCCode1 + model.BBCCode2;






              share|improve this answer























              • My model is an entity and it has only one member for this code and I want to be automatically populated when I edit the data.

                – Buda Gavril
                Nov 20 '15 at 13:45











              • you shouldn't use your entity as a view model. You should create a new view model class so you should use it in your view as model. After that populate data in your controller like my sample code.

                – Yargicx
                Nov 20 '15 at 14:11















              0














              You should use two property in your model.



              public class Data

              public int id get; set;
              public string BBBCode1 get; set;
              public string BBBCode2 get; set;


              <div class="col-md-10">
              @Html.EditorFor(model => model.BBBCode1, new htmlAttributes = new @class = "form-control" )
              @Html.ValidationMessageFor(model => model.BBBCode1, "", new @class = "text-danger" )
              </div>
              <div class="col-md-10">
              @Html.EditorFor(model => model.BBBCode2, new htmlAttributes = new @class = "form-control" )
              @Html.ValidationMessageFor(model => model.BBBCode2, "", new @class = "text-danger" )
              </div>


              in your controller



              public ActionResult Index(Data model)
              var bbcCode = model.BBCCode1 + model.BBCCode2;






              share|improve this answer























              • My model is an entity and it has only one member for this code and I want to be automatically populated when I edit the data.

                – Buda Gavril
                Nov 20 '15 at 13:45











              • you shouldn't use your entity as a view model. You should create a new view model class so you should use it in your view as model. After that populate data in your controller like my sample code.

                – Yargicx
                Nov 20 '15 at 14:11













              0












              0








              0







              You should use two property in your model.



              public class Data

              public int id get; set;
              public string BBBCode1 get; set;
              public string BBBCode2 get; set;


              <div class="col-md-10">
              @Html.EditorFor(model => model.BBBCode1, new htmlAttributes = new @class = "form-control" )
              @Html.ValidationMessageFor(model => model.BBBCode1, "", new @class = "text-danger" )
              </div>
              <div class="col-md-10">
              @Html.EditorFor(model => model.BBBCode2, new htmlAttributes = new @class = "form-control" )
              @Html.ValidationMessageFor(model => model.BBBCode2, "", new @class = "text-danger" )
              </div>


              in your controller



              public ActionResult Index(Data model)
              var bbcCode = model.BBCCode1 + model.BBCCode2;






              share|improve this answer













              You should use two property in your model.



              public class Data

              public int id get; set;
              public string BBBCode1 get; set;
              public string BBBCode2 get; set;


              <div class="col-md-10">
              @Html.EditorFor(model => model.BBBCode1, new htmlAttributes = new @class = "form-control" )
              @Html.ValidationMessageFor(model => model.BBBCode1, "", new @class = "text-danger" )
              </div>
              <div class="col-md-10">
              @Html.EditorFor(model => model.BBBCode2, new htmlAttributes = new @class = "form-control" )
              @Html.ValidationMessageFor(model => model.BBBCode2, "", new @class = "text-danger" )
              </div>


              in your controller



              public ActionResult Index(Data model)
              var bbcCode = model.BBCCode1 + model.BBCCode2;







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 20 '15 at 13:42









              YargicxYargicx

              5921723




              5921723












              • My model is an entity and it has only one member for this code and I want to be automatically populated when I edit the data.

                – Buda Gavril
                Nov 20 '15 at 13:45











              • you shouldn't use your entity as a view model. You should create a new view model class so you should use it in your view as model. After that populate data in your controller like my sample code.

                – Yargicx
                Nov 20 '15 at 14:11

















              • My model is an entity and it has only one member for this code and I want to be automatically populated when I edit the data.

                – Buda Gavril
                Nov 20 '15 at 13:45











              • you shouldn't use your entity as a view model. You should create a new view model class so you should use it in your view as model. After that populate data in your controller like my sample code.

                – Yargicx
                Nov 20 '15 at 14:11
















              My model is an entity and it has only one member for this code and I want to be automatically populated when I edit the data.

              – Buda Gavril
              Nov 20 '15 at 13:45





              My model is an entity and it has only one member for this code and I want to be automatically populated when I edit the data.

              – Buda Gavril
              Nov 20 '15 at 13:45













              you shouldn't use your entity as a view model. You should create a new view model class so you should use it in your view as model. After that populate data in your controller like my sample code.

              – Yargicx
              Nov 20 '15 at 14:11





              you shouldn't use your entity as a view model. You should create a new view model class so you should use it in your view as model. After that populate data in your controller like my sample code.

              – Yargicx
              Nov 20 '15 at 14:11











              0














              If you don't want to change the Model (no judgement)
              I used these two in my input field, one for both parts of the value:



              <div>@Html.TextBoxFor(m => m.Betrag, new @Value = Model.Betrag.ToString().Split(',').GetValue(0) )</div>

              <div>@Html.TextBoxFor(m => m.Betrag, new @Value = Model.Betrag.ToString().Split(',').GetValue(1) )</div>


              This simply splits up a value like '15,00' into a '15' and '00', you can then join the values together again afterwards with some Javascript and JQuery. This works great for me.






              share|improve this answer










              New contributor




              Bradley Weibel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.
























                0














                If you don't want to change the Model (no judgement)
                I used these two in my input field, one for both parts of the value:



                <div>@Html.TextBoxFor(m => m.Betrag, new @Value = Model.Betrag.ToString().Split(',').GetValue(0) )</div>

                <div>@Html.TextBoxFor(m => m.Betrag, new @Value = Model.Betrag.ToString().Split(',').GetValue(1) )</div>


                This simply splits up a value like '15,00' into a '15' and '00', you can then join the values together again afterwards with some Javascript and JQuery. This works great for me.






                share|improve this answer










                New contributor




                Bradley Weibel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






















                  0












                  0








                  0







                  If you don't want to change the Model (no judgement)
                  I used these two in my input field, one for both parts of the value:



                  <div>@Html.TextBoxFor(m => m.Betrag, new @Value = Model.Betrag.ToString().Split(',').GetValue(0) )</div>

                  <div>@Html.TextBoxFor(m => m.Betrag, new @Value = Model.Betrag.ToString().Split(',').GetValue(1) )</div>


                  This simply splits up a value like '15,00' into a '15' and '00', you can then join the values together again afterwards with some Javascript and JQuery. This works great for me.






                  share|improve this answer










                  New contributor




                  Bradley Weibel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.










                  If you don't want to change the Model (no judgement)
                  I used these two in my input field, one for both parts of the value:



                  <div>@Html.TextBoxFor(m => m.Betrag, new @Value = Model.Betrag.ToString().Split(',').GetValue(0) )</div>

                  <div>@Html.TextBoxFor(m => m.Betrag, new @Value = Model.Betrag.ToString().Split(',').GetValue(1) )</div>


                  This simply splits up a value like '15,00' into a '15' and '00', you can then join the values together again afterwards with some Javascript and JQuery. This works great for me.







                  share|improve this answer










                  New contributor




                  Bradley Weibel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  share|improve this answer



                  share|improve this answer








                  edited 13 hours ago









                  adiga

                  11.4k62545




                  11.4k62545






                  New contributor




                  Bradley Weibel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered 13 hours ago









                  Bradley WeibelBradley Weibel

                  11




                  11




                  New contributor




                  Bradley Weibel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  Bradley Weibel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  Bradley Weibel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.



























                      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%2f33828004%2fmvc-split-string-from-model-in-multiple-text-boxes%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