2

I have done some projects on MVC. I have a generic doubt.

  1. Can view create objects of model class in MVC pattern? For example, lets say we are designing MVC for taxi management system. We have classes for cab and passenger. View will be taking passenger and cab details from user.

  2. can we instantiate cab and passenger(model class) in view for storing details?

  3. If we cant instantiate then where should we store details after taking from user?

  4. How will it pass to controller?

    I am new to MVC and any help will be greatly appreciated. I have googled it many times but have not got the satisfactory answer.

2
  • Please do ask if you need any other clarifications Commented Sep 16, 2015 at 9:17
  • 1
    yes you can instantiate both classes in the view too. Commented Sep 16, 2015 at 9:18

1 Answer 1

2
  1. Yes we can create the objects of model class in view (but then we are going to kill the concept of MVC)
  2. We can save the object of model classes
  3. for client side you have to save the values of both class attributes and passs them by using ajax/form (post/get).
  4. How to pass the values Code

View HTML

 <div class="registrationForm">
      @using (Html.BeginForm("Registration", "Car", FormMethod.Post))
      {
          <p>
              <input type="text" name="carName" placeholder="Your Car Name"  />
          </p>
          <p>
              <input type="text"  name="carNum" placeholder="Re-enter Number"  />
          </p>

          <p>
              <input name="signup" type="submit" value="Submit">
          </p>
    }
  </div>

Controller Action

public ActionResult Registration(String carName, string carNum)
{
   // your logic
   return View();

}

Please modify if I am wrong.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks Muhammad. But the problem is I am working on complete CUI Based Java application. It is not using any HTML form or AJAX call. I have to design the MVC architecture ysing core java.
@user3681970: I am not have much experience in Java but there are many MVC framework already like Spring so you can use as API i.e. and use use them as you want :)
Yes muhammad. But it is a pure CUI application without using any framework magic and all.
@user3681970 what do you want to to do ? little explantion

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.