0

how do I open a new page with layout using jquery ajax? I need to return strName to my view in my controller.

My jquery ajax:

mvcJqGrid.demo.edit = function (id) {
     var urlEdit = '@Url.Action("Edit")';
        $.ajax({
        type:"GET",
        url:urlEdit,
        data:{strName: $('#customerGrid').jqGrid('getCell',id,'Client00130012')}
        });
    }

Edit: *my View Controller:*

public ActionResult Edit(string strName)
    {

        var q = from c in db.CanaClie0012
                join w in db.Clientes0013 on c.Client00130012 equals w.Client0013
                where c.Client00130012 == strName
                select new ClientModel
                {
                    CanaClie0012 = new CanaClie0012()
                    {
                        Client00130012 = c.Client00130012,
                        F1Pais00200012 = c.F1Pais00200012,
                        F1Cana02530012 = c.F1Cana02530012,
                        Direcc0012 = c.Direcc0012
                    },
                    Clientes0013 = new Clientes0013()
                    {
                        Client0013 = w.Client0013,
                        Nombre0013 = w.Nombre0013,
                        F1Pais00200013 = w.F1Pais00200013
                    }
                };

        return View(q);
    }
4
  • location.href = 'url' may be?
    – maxs87
    Commented Jun 14, 2013 at 12:26
  • window.location="Edit/" + $('#customerGrid').jqGrid('getCell',id,'Client00130012'); . I used this one in the success parameter of ajax. but i figured its not passing the value for my strName. if I use location.href how should i pass my strName parameter to my view?
    – Romeo
    Commented Jun 14, 2013 at 12:36
  • can you tell me what you try to do? As i can see you trying to redirect on record edit page using jqGrid by record id, right?
    – maxs87
    Commented Jun 14, 2013 at 12:48
  • Actually I need to pass a model to my edit page. Am i doing this in a right way?
    – Romeo
    Commented Jun 14, 2013 at 12:59

1 Answer 1

1

You doing it in a wrong way; If you want to open edit page with your model try next.

first you need build url link in your grid to open this edit page with Model.Id. In jqGrid you need use the column formater. After that you can click on link and open your edit page like 'site.com/controller/edit/6666'

colModel: [
{ name: 'ColumnName',
    formatter: function (cellvalue, options, rowObject) {
        return '<a href="/YourController/Edit/' + cellvalue + '">' + "Edit" + '</a>';
    } 
},

],

This should work.

4
  • your right about the href, thank you for that. but it did not fill my strName variable. as you can see in my view controller. I use the strName to select data from my EF model.
    – Romeo
    Commented Jun 14, 2013 at 13:52
  • if your link builded with id try public ActionResult Edit(string id) not strName. You route in global.asax probably maped to id.
    – maxs87
    Commented Jun 14, 2013 at 13:55
  • Thanks @maxs87 that solved my problem. one more question though what if I have multiple parameter in my view controller. lets say ActionResult Edit(string id, string name, string address). how should my return '<a href=""></a> should look like?
    – Romeo
    Commented Jun 14, 2013 at 14:09
  • if you have route configured for this you can use controller/action/111/222/333 but i think you have only default route. So href must looks like href='/controller/action/id?name=someName&address=someAddres'
    – maxs87
    Commented Jun 14, 2013 at 14:13

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.