1

In asp.net MVC getting the model value but while passing to view nothing displayed.

Controller

  public ActionResult Index(plan plan1)
        {
            var myCharge = new StripeChargeCreateOptions();

            string apiKey = "";
            var stripeClient = new StripeClient(apiKey);
            var planService = new StripePlanService(apiKey);
            StripePlan response = planService.Get("1234");
            plan1.Amount = (response.Amount).ToString();

            return View();
        }

view

<div>
    @Html.TextBoxFor(m => m.Amount)

</div>

How to display the Amount value inside textbox

2
  • 1
    You need to parse in an object(model) to the view. Commented Jul 4, 2017 at 12:23
  • 1
    return View(plan1); You missed the data. Commented Jul 4, 2017 at 12:23

3 Answers 3

2

Hope your View is strongly bound with the Model class (the instance is plan1). So, You need to specify your model in your return statement

return View(plan1);
Sign up to request clarification or add additional context in comments.

Comments

1

It is because you are not passing hte model object back to view, you need to pass the instance plan1 back to view from action, just change your last line of action code to :

return View(plan1);

The View gets information about the model object which is passed from the controller action, you are not passing it back, so there is no way for View to know that it needs to use plan1 object state to render the View.

I hope it makes sense to you now that why it is not displaying your data.

Comments

1

The answer is already given. You should return the model bij calling

return View(plan1);

It's better to return a ViewModel instead of your model to your view.

  public class PlanViewModel
  {
     public plan plan1 { get; set; }
  }




public ActionResult Index(plan plan1)
{
   var myCharge = new StripeChargeCreateOptions();

   string apiKey = "";
   var stripeClient = new StripeClient(apiKey);
   var planService = new StripePlanService(apiKey);
   StripePlan response = planService.Get("1234");
   plan1.Amount = (response.Amount).ToString();

   var viewModel = new PlanViewModel {
      plan1 = plan1
   };

   return View(viewModel);
}

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.