0
votes

ViewModel

  public class ModelTypeViewModel
  {
     public virtual  CheckRadioButton CRB { get; set; }


}

Controller

public class M1Controller : Controller
 {
    public CarContext db = new CarContext(); 

    private CheckRadioButton get()
    {
        CheckRadioButton c = new CheckRadioButton();
        c.BrandName = "abc";
        c.type = "xyz";
        return c; 

    }
  public ActionResult Hello ()
    {
        CheckRadioButton s = get();
        ModelTypeViewModel mm = new ModelTypeViewModel(s);


        return View(mm);

    }

View:(Hello)

@model Car.Models.ModelTypeViewModel
@Html.Partial("_Display", Model.CRB) 

Partial View(_Display)

<h1> Hello </h1>

How can I pass diff model each time to to partial view?

It gives an error

"An exception of type 'System.Web.HttpParseException' occurred in System.Web.WebPages.Razor.dll but was not handled in user code"

It gives the same error even if I pass only 'Model" I am confused

1
You have to give a bit more info than just that. The code you have shown will work fine if the model your passing to the _Display.cshtml view is correct. - user3559349
In controller : public ActionResult Hello () {return view ()} In View: @model Car.Models.ModelTypeViewModel @{Html.Partial("_Display", Model.)} In Partial View : <h1> Hi</h1> It's just a basic stuff, I don't know why isn't it working. - Nil
post your Models without it, the question can not be answered correctly - anand

1 Answers

0
votes

Put each button inside Ajax.BeginForm

@using (Ajax.BeginForm("BuyItem", "MsmqTest"}, new AjaxOptions { UpdateTargetId = "msmqpartial" }))
{ <button type="submit">Buy</button>}
@using (Ajax.BeginForm("BuyItem", "MsmqTest" }, new AjaxOptions { UpdateTargetId = "msmqpartial" }))
{
    <button type="submit">Sell</button>
}

Where "updateTargetId" is the div id to append content

 public ActionResult BuyItem()
        {
        if(//some condition goes here)
            return PartialView("Partial1",data);
        if(//some condition goes here)
           return PartialView("Partial2",data);
        }