I'm just starting out with MVC, done a quite a bit of WebForms so not a noob.
So far MVC is fairly intuitive and I'm catching on pretty quick but I'm stuck on one critical area;
I've set up a
bootstrap-tagsinput[
^] control on my view page and I'm able to collect the data in a JQuery function.
I've set up a ViewModel class and can pass values into and show them on the control but I'm stuck as to how to return these values to the controller??
Here's my view code;
@model JaxCoderV20.Models.PostViewModel
@{
ViewBag.Title = "Home Page";
}
@using (Ajax.BeginForm("Calculate", "Home",
new AjaxOptions { UpdateTargetId = "divInterestDeatils" }))
{
<div class="page-body">
<div class="row">
<div class="col-lg-6 col-sm-6 col-xs-12">
<div class="well with-header">
<div class="header bordered-darkorange">Bootstrap Tags Input</div>
<div>
<input type="text" value="@Html.Encode(Model.TestStringData) " data-role="tagsinput" placeholder="Add tags" />
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
</div>
</div>
</div>
}
@section PageScripts{
<!--
<script src="/assets/js/tagsinput/bootstrap-tagsinput.js"></script>
<script>
$( document ).ready(function() {
$('form').on('submit',function()
{
@Model.TestStringData = $('input').tagsinput('items')
});
});
</script>
}
Then in the controller I have;
[HttpPost]
public ActionResult Calculate(PostViewModel model)
{
return Content("This is a test");
}
}
and just for good measure here's my PostViewModel code;
namespace JaxCoderV20.Models
{
public class PostViewModel
{
public Post PostData { get; set; }
public Message MsgData { get; set; }
public List<string> TestData { get; set; }
public string TestStringData { get; set; }
}
}
I have a break on the post and it happens but all fields in the PostViewControl are null.
I also put a break at the script and there is valid data there.
Thanks